AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 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 Your Reply Post New Question

 Viewer's Reply
Set DataKeyNames value
Answered By Moderator1 on 2/14/2008 12:20:57 AM
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.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!
Building a Web Application Security Program
Many .NET teams are underperforming, is yours?