日期:2014-05-19  浏览次数:20515 次

一个关于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;
}
}
}