任何人都可以帮助我如何在 asp 中的 gridview 中添加新记录,这是我的代码:
Partial Class _Default
Inherits System.Web.UI.Page
Dim drow As DataRow
Dim dt As New DataTable
Dim x As Integer
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
drow = dt.NewRow
drow("fname") = TextBox1.Text
drow("mname") = TextBox2.Text
drow("lname") = TextBox3.Text
dt.Rows.Add(drow)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
binds()
End If
End Sub
Protected Sub binds()
dt.Columns.Add("fname")
dt.Columns.Add("mname")
dt.Columns.Add("lname")
drow = dt.NewRow
drow("fname") = TextBox1.Text
drow("mname") = TextBox2.Text
drow("lname") = TextBox3.Text
dt.Rows.Add(drow)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
End Class
当我单击按钮时,错误表明 fname 不属于该表。谢谢