【发布时间】:2012-03-07 00:54:48
【问题描述】:
我有一个带有文本框和“添加”按钮的表单。
- 用户可以在文本框中写下一个名称,然后单击“添加”按钮。它将保存在具有自动 ID 的数据表中。
- 之后,文本框被清除,用户可以在文本框中输入另一个名称并单击按钮。
- 这应该添加到内存中现有 ID + 1 的现有数据表中。
- 然后在网格视图中显示。 (这只是为了显示目的,以确认它有效)
我有一个这样的数据表。
Button1.click() event
Dim name = txtname.Text
Dim dt As New DataTable
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
Dim N As Integer = dt.Columns("ID").AutoIncrement
dt.Rows.Add(N, name)
GridView1.DataSource = dt
GridView1.DataBind()
txtname.Text = ""
目前我有一段时间喜欢上面的代码。在实际程序中,它不仅仅是名称,也不仅仅是一个数据表,所以我只是模拟了一些代码。
还有这个aspx代码。
<asp:TextBox ID="txtname" runat="server">
</asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
谁能建议我怎么做?我知道我的代码是废话而且不正确,但我只需要输入一些代码,这样你们就不需要为我从头开始工作。
非常感谢。
【问题讨论】:
-
我不敢相信我问了这个问题:(