日期:2014-05-17  浏览次数:20457 次

关于GridView中图片选择显示的问题。
各位大大,我有一个GridView其中第一列数据绑定了一列数据,其中内容是“正常”or “非正常”,现在我想在第二列里自动选择显示图片。

e.Row.Cells[2].Text通过以下的代码,已经可以正常显示“坏的”了,

问题是e.Row.Cells[2]没有ImageUrl这个属性,请问一下这里要怎么描述啊?



C# code


    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"  
               }

        }

  }





------解决方案--------------------
.Row.Cells[2].ImageUrl ??Cell对象(类)什么时候有ImageUrl属性了?

你是想说在模板列中使用Image控件吧。你可以在绑定表达式中这样设计
HTML code
ImageUrl='<%# GetUrl((bool)Eval("状态")) %>'

------解决方案--------------------
用模板,里面放个image控件。