<asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 10px; position: absolute;
            top: 204px" Width="659px">
            <Columns>
                <asp:TemplateField HeaderText="卡片名称">
                  <ItemTemplate>
                    <asp:Label id="CardName" runat="server">
                    </asp:Label>
                  </ItemTemplate>
想得到Lable控件的ID。顺便给他赋值。 Label lb = Page.FindControl("GridView1").FindControl("CardName") as Label;
Label  lb=this.Findcontrol("CardName") as Lable 
错误。: 未将对象设置到对象实例。 空指针异常。  在线等。 求解

解决方案 »

  1.   

    Label lb = (Label)GridView1.Rows[i].FindControl("CardName")
    这样查找i是行索引  看你找哪行的了
      

  2.   

     Label mc = (Label)(GV_kc.Rows[i].FindControl("CardName"));
    绝对没有问题
      

  3.   

    for (int i=0;i<Gridview1.Rows.Count;i++)
    {
      Label mc = (Label)(GridView.Rows[i].FindControl("CardName")); 
    }
      

  4.   

    在GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if(e.Row.RowType == DataControlRowType.DataRow)
      {
        Lable lable1=e.Row.FindControl("lable1") as Lable ;
      }
    }
      

  5.   


    还是不行啊~~mc一直为null