views:

241

answers:

1

Hi All,

I am using gridview for add and update process in database.

Process Flow:

Name  A   B   C  Command

xx                        Add

yy    12   13  13 Update

zz    22   33  44 Update

  1. The first record does not have value in datakey field because there is no record in the database
  2. The Second record has data key because it has the record available.
  3. I want to update the datakey field value of the gridview after add process done
A: 

I'm not sure if this is what you're asking about; but the row's DataKey field in a GridView is updated every time you bind the GridView to a data source, calling the DataBind() method.

So, after you have added a new record, just load the data source and bind the GridView to it, and the DataKey fields will have the new values.

alexphi
Thank you for your reply. Is it possible to update the datakey value without rebinding the gridview?
Geetha
That's not possible. Just look at the DataKey.Value property: it's a get-only property.
alexphi