|
页面:
<ext:Grid ID="gridCustomerPlan" Title="客户邀约计划" ShowBorder="false" AutoScroll="true"
ShowHeader="false" EnableRowNumber="True" runat="server" DataKeyNames="WEBID"
Height="150px" Width="1100px">
<Toolbars>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="btnCustomerPlan" runat="server" Text="添加空行" EnableAjax="true" Hidden="false"
Icon="Add">
</ext:Button>
</Items>
</ext:Toolbar>
</Toolbars>
<Columns>
<ext:TemplateField HeaderText="ID" Width="100px" Hidden="true">
<ItemTemplate>
<asp:TextBox ID="txtWEBID_P" runat="server" Width="80px" TabIndex='<%# Container.DataItemIndex + 10 %>'
Text='<%# Eval("WEBID") %>'>
</asp:TextBox>
</ItemTemplate>
</ext:TemplateField>
<ext:TemplateField HeaderText="来源" Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtPERSON_SOURCE" runat="server" Width="80px" TabIndex='<%# Container.DataItemIndex + 10 %>'
Text='<%# Eval("PERSON_SOURCE") %>'>
</asp:TextBox>
</ItemTemplate>
</ext:TemplateField>
<ext:TemplateField HeaderText="预估人数" Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtPERSON_NUM" runat="server" Width="80px" TabIndex='<%# Container.DataItemIndex + 10 %>'
Text='<%# Eval("PERSON_NUM") %>'>
</asp:TextBox>
</ItemTemplate>
</ext:TemplateField>
</Columns>
</ext:Grid>
后台:
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
|
|