当前位置: 代码迷 >> ASP.NET >> 一个关于GRIDVIEW的有关问题,大家帮忙看看
  详细解决方案

一个关于GRIDVIEW的有关问题,大家帮忙看看

热度:6886   发布时间:2013-02-26 00:00:00.0
一个关于GRIDVIEW的问题,大家帮忙看看
gridview的一个column内有label,image1和image2三个控件
当label.text=1时,image1可见
当label.text=0时,image2可见
我这样写似乎没有成功,大家看看是什么问题
  protected   void   GridView1_RowDataBound(object   sender,   GridViewRowEventArgs   e)
        {
                Label   lb   =   (Label)e.Row.Cells[0].FindControl( "label1 ");
                //string   yo   =   trf.Text.ToString();
                Image   im1   =   (Image)e.Row.Cells[0].FindControl( "Image1 ");
                Image   im2   =   (Image)e.Row.Cells[0].FindControl( "Image2 ");
               
                if   (lb.Text.Equals( "0 "))
                {
                        im2.Visible   =   true;
                }
                else
                {
                        im1.Visible   =   true;
                }
        }

------解决方案--------------------------------------------------------
protected void GrvInfoList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
Label lb = (Label)e.Row.Cells[0].FindControl( "label1 ");
//string yo = trf.Text.ToString();
Image im1 = (Image)e.Row.Cells[0].FindControl( "Image1 ");
Image im2 = (Image)e.Row.Cells[0].FindControl( "Image2 ");

if (lb.Text.Equals( "0 "))
{
im2.Visible = true;
}
else
{
im1.Visible = true;
}
}
}