Adding an item to the datagrid

C

Chris Leuty

I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button
underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables("Trades").NewRow ' create
new row
dsTrades.Tables("Trades").Rows.Add(drNew)
' add new row to table
drNew("TradeName") = Request.Form("txtNewTrade") '
get TradeName from post
daTrades.Update(dsTrades)
' update database
daTrades.Fill(dsTrades)
' re-load the sorted list...
dgTrades.DataBind()
' bind the grid

The item adds properly to the database, but the newly added item always
appears as the first row in the grid, if the grid is currently on the first
page, regardless of where it should appear (it is a sorted list). Calling
the grid page again fixes the problem (i.e. the item begins to show up in
the correct place). My basic question is: why doesn't the Fill() and
DataBind() when I am adding refresh the grid before rendering?

Thanks,

Chris
 
J

John Saunders

Chris Leuty said:
I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button
underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables("Trades").NewRow ' create
new row
dsTrades.Tables("Trades").Rows.Add(drNew)
' add new row to table
drNew("TradeName") = Request.Form("txtNewTrade") '
get TradeName from post
daTrades.Update(dsTrades)
' update database
daTrades.Fill(dsTrades)
' re-load the sorted list...
dgTrades.DataBind()

Why would this be sorted?
 
C

Chris Leuty

Technical Why: The proc returning the data is sorting the data
alphabetically. (It is a list of trade skills).
Business Why: That is how they want to see the data.
 
C

Chris Leuty

I cleared the dataset before filling it, and the grid refreshed in the
correct order.

All fixed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top