GridView1中的ItemTemplate里有个Label6,如何得到这个控件的text值

解决方案 »

  1.   

    Label l=GridView1.Rows[第几行].Cells[第几列].FindControl("Label6") as Label;
      

  2.   

    protected void Gridview2_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      if (e.Row.RowType == DataControlRowType.DataRow && this.gvUsers.EditIndex != e.Row.RowIndex)
      {
      Label lbsuoding = (Label)e.Row.Cells[4].FindControl("Label6");
      }
      }
      

  3.   


                Label lbl = GridView1.FindControl["label6"] as Label;
                string lblName=lbl.Text; 
      

  4.   

    GridView1.FindControl("Label6") as Label;或者:
    frach(control c in GridView1.Control)
    {
    if(c is Lable){
       Lable lable =  c.FindControl("Label6") as Lable;
       lable.text;
    }
    }
      

  5.   

    獲取對象
    Label lbl = GridView1.FindControl["label6"] as Label;
      

  6.   

    Label lbl = GridView1.FindControl["label6"] as Label;
      string lblName=lbl.Text; 
      

  7.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            SqlDataReader sdr = db.reDataReader("select * from advicereply");
            if (sdr.Read())
            {
                if (string.IsNullOrEmpty(sdr["reply"].ToString()))
                {
                    Label reply = GridView1.FindControl("Label6") as Label;
                    reply.Text = "未回复";
                }
                else
                {
                    Label replied = GridView1.FindControl("Label6") as Label;
                    replied.Text = "已回复";
                }
            }
        }
    那我要直接赋值,这样貌似不对,要怎么改?
      

  8.   


       if (e.Row.RowType == DataControlRowType.DataRow && this.gvUsers.EditIndex != e.Row.RowIndex)
       {
       Label lbsuoding = (Label)e.Row.Cells[4].FindControl("Label6");
       }
       
      

  9.   

    Label lbl = GridView1.FindControl["label6"] as Label;
    我都习惯用这个