如何从Repeater中的文本框控件获取值

时间:2016-12-15 14:36:49

标签: asp.net

我有项目模板的转发器:

<asp:Repeater runat="server" ID="rpGiaiThuong">
  <ItemTemplate>
    <div class="giaithuong">
      <asp:HiddenField runat="server" Value='<%#Eval("MaGiaiThuong")%>' />
      <input type="checkbox" value='<%#Eval("MaGiaiThuong")%>' id='<%#Eval("MaGiaiThuong")%>' />
      <span><%#Eval("TenGiaiThuong")%> </span>
      <asp:TextBox runat="server" ID="txtGiaTri" CssClass="form-control">                 
      </asp:TextBox>
    </div>
  </ItemTemplate>
</asp:Repeater>

如何在codebehind(c#)获取TextBox的ID?

1 个答案:

答案 0 :(得分:0)

foreach (RepeaterItem item in rpGiaiThuong.Items)
{
      TextBox txtName = (TextBox)item.FindControl("txtGiaTri");
      if(txtName!=null)
      {
      //do something with txtName.Text
      }
}