HighTechTalks DotNet Forums  

Problem with Adding a new row to an exiting datagrid

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Problem with Adding a new row to an exiting datagrid in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
C
 
Posts: n/a

Default Problem with Adding a new row to an exiting datagrid - 11-29-2007 , 12:07 PM







Hello,

The existing data table binded to a grid works When I enter the number of
line items I need and click on a button that say make grid. The problem is
when click on Add Rows the extra row does not appear. I think I am having a
problem with the databind, because if I use, gvParts.DataBind(), the existing
datagrid goes away.


Thank you in advance,

Existing Code used to create the data table to add records (WORKS)
************************************************** ********
Protected Sub btnMkGrid_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles btnMkGrid.Click
Dim dt As New Data.DataTable
'Dim tblReceiving As Table
dt.Columns.Add(New Data.DataColumn("LineNO"))
For i As Integer = 1 To tbItems.Text
Dim dr As Data.DataRow
dr = dt.NewRow
dr("LineNO") = i
dt.Rows.Add(dr)
Next
'Bind the DataTable to the DataGrid
gvParts.DataSource = dt
gvParts.DataBind()

End Sub

************************************************** **
Does Not Work
Protected Sub AddRow_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles AddRow.Click

'Add the number of rows specified by "RowCount" to gvParts
If (IsNumeric(RowCount.Text)) Then
Dim i As Integer
For i = 1 To CInt(RowCount.Text)

'Adding a blank record to the dataset.
Dim dt As New Data.DataTable
dt.Columns.Add(New Data.DataColumn("LineNO"))
Dim dr As Data.DataRow
dr = dt.NewRow
dr("LineNO") = i
dt.Rows.Add(dr)

Next
End If
'Rebind the grid to show the newly added row(s).
'gvParts.DataBind()
'DataBind()

End Sub


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.