0
我試圖訪問label
和textbox
的值DataList
使用Findcontrol
。在運行程序時,我得到的值爲label
正確,但從textbox
控制中沒有任何值。下面是代碼從datalist findcontrol中得到正確的文本框的值
的.aspx代碼
<asp:DataList ID="SubjectAdded" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="SubjectLbl" runat="server" Text='<%# Eval("subject") %>'</asp:Label>
</td>
<td>
<asp:TextBox ID="FeeBox" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
.aspx.cs代碼
for(int i=0; i<SubjectAdded.Items.Count; i++)
{
string feeTB = ((TextBox)SubjectAdded.Items[i].FindControl("FeeBox")).Text;
string subjectNameLb = ((Label)SubjectAdded.Items[i].FindControl("SubjectLbl")).Text ;
string str = "UPDATE table name SET FEE='" + feeTB + "' WHERE TUTOR = '" + id+ "' AND SUBJECT = '" + subjectNameLb + "'";
SqlCommand strCmd = new SqlCommand(str, con);
con.Open();
strCmd.ExecuteNonQuery();
con.Close();
}