关于GridView中图片选择显示的问题。
各位大大,我有一个GridView其中第一列数据绑定了一列数据,其中内容是“正常”or “非正常”,现在我想在第二列里自动选择显示图片。
e.Row.Cells[2].Text通过以下的代码,已经可以正常显示“坏的”了,
问题是e.Row.Cells[2]没有ImageUrl这个属性,请问一下这里要怎么描述啊?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Convert.ToString(e.Row.Cells[1].Text.Trim()) != "正常" && e.Row.Cells[19].Text != "True") { e.Row.Cells[2].BackColor = Color.Red; e.Row.Cells[2].Text="坏的"; e.Row.Cells[2].ImageUrl = "Images/huai.gif" } } }ImageUrl='<%# GetUrl((bool)Eval("状态")) %>'
[解决办法]
用模板,里面放个image控件。