我在解决方案浏览器的两个图像在该位置处显示图像 -DataGridView的细胞返回NULL,而试图在数据网格细胞
〜/图像/ Active.jpg & 〜/图像/ Inactive.jpg
我想显示这些图像在我的网格视图单元取决于单元格值,即“活动”或“无效”。
我至今尝试下面给出:
GridView的代码在页面源文件:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnDataBound="GridView1_DataBound1" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" >
<Columns>
<asp:BoundField DataField="ServerName" HeaderText="ServerName" SortExpression="ServerName" />
<asp:BoundField DataField="Application" HeaderText="Application" SortExpression="Application" />
<asp:BoundField DataField="Instance" HeaderText="Instance" SortExpression="Instance" />
<asp:BoundField DataField="Environment" HeaderText="Environment" SortExpression="Environment" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="imgID" imageurl="" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
代码隐藏文件.aspx.cs:
foreach (GridViewRow row in GridView1.Rows)
{
if (row.Cells[4].Text == "Active")
{
Image img = (Image)row.FindControl("imgID");
img.ImageUrl= "";
}
else
{
Image img = (Image)row.FindControl("imgID");
img.ImageUrl = "~/Images/Inactive.jpeg";
}
}
请注意,我不能使用rowdatabound。我已经写了上面的代码中的一个函数,我正在检查一些东西,并将单元格值更新为Active或Inactive。
出现的问题是DataGrid的Cell返回图像的空值。
请建议解决方案来解决这个问题。
为什么你分配空 - 'img.ImageUrl =“”;'为活动?它应该是'“〜/ Images/Inactive.jpeg”;'? –
为什么不能使用行数据绑定事件? – Saurabh
@KarthickRaju,那真是空虚。但即使我把网址,它不工作。 –