我有项目模板的转发器:
<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?
答案 0 :(得分:0)
foreach (RepeaterItem item in rpGiaiThuong.Items)
{
TextBox txtName = (TextBox)item.FindControl("txtGiaTri");
if(txtName!=null)
{
//do something with txtName.Text
}
}