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

解决方案 »

  1.   

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

  2.   

    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 == "0")
            {
                im1.Visible = false;
                im2.Visible = true;
            }
            else
            {
                im1.Visible = true;
                im2.Visible = false;
            }
        }
      

  3.   

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

  4.   

    你程序的问题是一旦一个img显示了,就不能隐藏了。