Private Sub InitCustomerPlanTable()
Dim dt As New DataTable("Table5")
With dt
.Columns.Clear()
.Columns.Add(New DataColumn("WEBID", Type.GetType("System.String")))
.Columns.Add(New DataColumn("PERSON_SOURCE", Type.GetType("System.String")))
.Columns.Add(New DataColumn("PERSON_NUM", Type.GetType("System.String")))
End With
Dim row As DataRow = dt.NewRow()
dt.Rows.Add(row)
dt.AcceptChanges()
gridCustomerPlan.DataSource = dt
gridCustomerPlan.DataBind()
End Sub
'获取当前表格数据
Public Function GetDataFromCustomerPlanGrid() As DataTable
Dim dt As New DataTable("Table5")
With dt
.Columns.Clear()
.Columns.Add(New DataColumn("WEBID", Type.GetType("System.String")))
.Columns.Add(New DataColumn("PERSON_SOURCE", Type.GetType("System.String")))
.Columns.Add(New DataColumn("PERSON_NUM", Type.GetType("System.String")))
End With
For i As Integer = 0 To gridCustomerPlan.Rows.Count - 1
Dim gRow As GridRow = gridCustomerPlan.Rows(i)
Dim newRow As DataRow = dt.NewRow()
newRow(0) = DirectCast(gRow.FindControl("txtWEBID_P"), System.Web.UI.WebControls.TextBox).Text
newRow(1) = DirectCast(gRow.FindControl("txtPERSON_SOURCE"), System.Web.UI.WebControls.TextBox).Text
newRow(2) = IIf(IsNumeric(DirectCast(gRow.FindControl("txtPERSON_NUM"), System.Web.UI.WebControls.TextBox).Text) = False, 0, DirectCast(gRow.FindControl("txtPERSON_NUM"), System.Web.UI.WebControls.TextBox).Text)
dt.Rows.Add(newRow)
Next
dt.AcceptChanges()
Return dt
End Function
'添加行按钮
Protected Sub btnCustomerPlan_Click(sender As Object, e As EventArgs) Handles btnCustomerPlan.Click
Dim dt As DataTable = GetDataFromCustomerPlanGrid()
Dim newRow As DataRow = dt.NewRow()
dt.Rows.Add(newRow)
gridCustomerPlan.DataSource = dt
gridCustomerPlan.DataBind()
End Sub 作者: erp8@live.cn 时间: 2013-6-9 14:51
好!! 增改删都可以了