|
-
Apr 7th, 2009, 03:36 PM
#1
Thread Starter
New Member
[RESOLVED] Add a new row in a GridView
EDIT: forgot to mention, so better state this before anything else... I'm running VS 2005 with Framework 2.0.
Hello all,
I have a GridView (gdvN) with 7 columns (N1, N2, N3, N4, Edit command e um Delete command). In the same aspx, 4 textbox (that would be a new line with new N1, N2, N3 and N4 values.).
After filling the textboxes and pressing a button, it was supposed to insert a Row in the gdvN.
The code I wrote is below:
Code:
Dim tbl As Table
Dim newindex as Int32 = 0
table = DirectCast(gdvN.Controls(0), Table)
For Each _item In gdvN.Rows
newindex += 1
Next
Dim _newitem As New TableRow
_newitem = New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Insert)
_newitem.Cells(1).Text = txtN1.text
_newitem.Cells(2).Text = txtN2.text
_newitem.Cells(3).Text = txtN3.text
_newitem.Cells(4).Text = txtN4.text
tbl.Rows.AddAt(newindex, _newitem)
When i try to run this, I notice that _newitem is created but has Cells.Count = 0. I thought it was a matter of "copying" a similar row, so I added:
Code:
_newitem = gdvN.Rows(0)
Unfortunately that didn't solved, as it edits an existing row instead of adding one. As I can see, that may be two paths for this to be solved:
Is there a way to make _newitem be created with the same structure as the gdvN rows. I didn't found how.
Or there's another logic (or a mistake in the coding) I'm not looking?
Last edited by garavello; Apr 7th, 2009 at 03:59 PM.
Reason: Adding Vs and Framework versions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|