日期:2014-05-18  浏览次数:20962 次

GridView 怎样找单元格的第二个控件
做了一个GridView
HTML code
 
<asp:TemplateField HeaderText="规格">
  <ItemTemplate>
  <asp:Label ID="lblg" runat="server"><%#DataBinder.Eval(Container.DataItem, "wlh")%></asp:Label>
  
  </ItemTemplate>
      <EditItemTemplate>
          <asp:TextBox ID="txtL" runat="server" Width="30px"></asp:TextBox>
          <asp:TextBox ID="txtW" runat="server" Width="30px"></asp:TextBox>
          <asp:TextBox ID="txtH" runat="server" Width="30px"></asp:TextBox>
      </EditItemTemplate>
 
  </asp:TemplateField>

在RowUpdating事件中怎样获取txtW和txtH的值
C# code
 
             int i = e.RowIndex;
             string l = ((TextBox)(gvapply.Rows[i].Cells[2].Controls[1])).Text.ToString();
        string w = ((TextBox)(gvapply.Rows[i].Cells[2].Controls[2])).Text.ToString();
        string h =  ((TextBox)(gvapply.Rows[i].Cells[2].Controls[3])).Text.ToString();
     

第一个textbox的值可以取到,但是后面的就取不到了····
  哪里错了??谢谢~

------解决方案--------------------
有ID,可以直接用((TextBox)gvapply.Rows[i].FindControl(ID)).Text