C# Can';无法从文本框中获取数据
我试图从文本框中获取数据,但它显示未定义的id或类似的内容。这是我的密码。我不明白问题出在哪里。Text1、Text2和Text3是我的文本框idC# Can';无法从文本框中获取数据,c#,asp.net,C#,Asp.net,我试图从文本框中获取数据,但它显示未定义的id或类似的内容。这是我的密码。我不明白问题出在哪里。Text1、Text2和Text3是我的文本框id SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter); DataSet thisDataSet = new DataSet(); thisAdapter.Fill(thisDataSet, "Odunc"); DataRow thisRo
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "Odunc");
DataRow thisRow = thisDataSet.Tables["Odunc"].NewRow();
thisRow["Book_Name"] = "" + Text1.Text;
thisRow["Reader_Name"] = "" + Text2.Text;
thisRow["Expiration_Date"] = "" + Text3.Text;
thisDataSet.Tables["Odunc"].Rows.Add(thisRow);
thisAdapter.Update(thisDataSet, "Odunc");
asp部件
<table style="width:100%;">
<tr>
<td class="style1">
Name of Reader</td>
<td>
<input id="Text1" name="Text1" type="text" /></td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Name of Book</td>
<td>
<input id="Text2" name="Text2" type="text" /></td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Expiration Date</td>
<td>
<input id="Text3" name="Text3" type="text" /></td>
<td>
</td>
</tr>
</table>
读者姓名
书名
到期日期
您需要将runat=“server”
添加到要使用服务器代码访问的输入元素中
示例
<%-- markup --%>
<input runat="server" id="Text1" name="Text1" type="text" />
// server code
string value = this.Text1.Value; // not ".Text"
//服务器代码
字符串值=this.Text1.value;//不是“.Text”
或者,您可以使用服务器控件
asp:Textbox
将文本框设置为服务器端控件。为什么不使用asp控件
<asp:TextBox ID="txtExample" runat="server" />
如果它们不是服务器控件,则需要从表单集合中提取值
txtExample.Text = "Test";