2016-12-15 58 views
0

我有一個項目模板轉發:如何從TextBox控件值直放站

<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> 

我怎樣才能在代碼隱藏獲取文本框的ID(C#)?

+1

[FindControl](https://msdn.microsoft.com/en-us/library/486wc64h(v = vs.110).aspx)可能會給你。 –

回答

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

雖然這段代碼可能回答這個問題,但提供關於爲什麼和/或代碼如何回答這個問題的附加上下文會提高它的長期價值。不鼓勵使用僅有代碼的答案。 – Ajean

+0

即使這個問題? – osmanraifgunes