我正在尝试读取每个 TextBox 的值,但收到一条错误消息:'TextBox2' is not delared。由于其保护级别,它可能无法访问。
前面的代码:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="equipment_note" SortExpression="equipment_note">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Text="Button2" />
</EmptyDataTemplate>
</asp:GridView>
还有更简单的代码:
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim strTextBoxValue1 As String = TextBox1.Text
Dim strTextBoxValue2 As String = TextBox2.Text
Dim strTextBoxValue3 As String = TextBox3.Text
Response.Write(strTextBoxValue1)
End Sub
'Dim strTextBoxValue1 As' 等行工作正常,但 value2 和 value3 都显示相同的错误,表示它们未声明。
如何在后面的代码中读取/检索 TextBox2 和 TextBox3 的值?