Label lxbhLabel = (Label)e.Item.FindControl("lxbhLabel1");
lxbhLabel.Text = "自动生成";  
TextBox lxbhLabel = (TextBox)e.Item.FindControl("lxmcTextBox");
lxbhLabel.Text = "自动生成";
为什么可以FindControl()到前台的TextBox,而不能FindControl到前台的Label呢?我保证ID没写错,看了好多遍了!!

解决方案 »

  1.   

      <EditItemTemplate>
                <tr>
                    <td>
                        <asp:Button ID="UpdateButton" ValidationGroup="edit" runat="server" CommandName="Update" Text="更新" />
                        <asp:Button ID="CancelButton" ValidationGroup="edit" runat="server" CommandName="Cancel" Text="取消" />
                    </td>
                    <td>
                        <asp:Label ID="lxbhLabel1" ValidationGroup="edit" runat="server" Text='<%# Eval("lxbh") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="lxmcTextBox" ValidationGroup="edit" runat="server" Text='<%# Bind("lxmc") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="edit" ControlToValidate="lxmcTextBox" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
                    </td>
                </tr>
            </EditItemTemplate>
      

  2.   

    搜一下你的设计代码中还有没有另外一个TextBox其ID也是lxmcTextBox?!
      

  3.   

    测试过没问题,可以取到lxbhLabel1
      

  4.   

    您是在ItemCreate()方法里面添加的函数吗?
      

  5.   

    没有啊,在EditItemTemplate模板里面自动生成的
    <td>
                        <asp:Label ID="lxbhLabel1" runat="server" Text='<%# Eval("lxbh") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="lxmcTextBox" runat="server" Text='<%# Bind("lxmc") %>' />
                    </td>
    为什么一个是Label,而另一个是TextBox?
      

  6.   


    string labelName;
    foreach(Control con in this.form1.Controls)
    {
      if(con.getType()==typeof(Label))
      {
       labelName+=con+";";
      }
    }
    Lz可以看看,在那个字符串里,看能不能找到那个叫lxbhLabel1的控件的ID,看看怎么回事。