AspdotnetCodes.com
US and UK Data Centers – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 Getting identity column of a inserted row in gridview
Posted by nivedita on  2/13/2008 9:09:58 AM Category: ADO.NET
Add to my favorites
Email to friend
  
How can i get the identity of a row inserted in gridview and
pass it to another webpage.
Hope somebody could help me.

Thanks,
Nivedita.

Post Answer Post New Question

 Viewer's Answers
Set DataKeyNames value
Posted By Moderator1 on 2/14/2008 12:20:57 AM
Description:
Hi,

Set DataKeyNames property of the GridView to your Identity column name. Then you can use that value as follows in you code-behind.

int RowIndex=Convert.ToInt32(e.CommandArgument);
hypNextPage.NavigateUrl="NextPage.aspx?id="+GridView1.DataKeys[RowIndex].Value;

You have write this in the ItemDataBound or ItemCommand event.
 
Sponsored by