Click here to Skip to main content
16,004,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guyz .

I just want to get the primary key value of the row that has been selected by user .
I have a button which the user can click upin which i want to pass the id to a new page.

is there any way to get the data out ?

I found gridview rows.cells[cell no];

but this doesnt work for hidden columns.

I just wanna have the paging sorting functionalities ,istead of having to create them in a repeater.
Posted
Comments
navanit_kamble 2-Oct-11 14:29pm    
that link really worked man thanks.

I am using the 4th method .

 
Share this answer
 
Comments
Simon Bang Terkildsen 2-Oct-11 14:20pm    
+5
André Kraak 2-Oct-11 14:25pm    
Thanks.
hey Navanit,

Assign Primarykey column name to DatakeyName property of GridView and try this on selectedIndexchanged event of GridView

C#
int _gCode;
_gCode = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();



or u can use this also..

C#
int j = GridView1.SelectedRow.RowIndex;
       _gCode = Convert.ToInt32(GridView1.DataKeys[j].Value);



hope this help u.
 
Share this answer
 
v2
Comments
navanit_kamble 6-Oct-11 9:16am    
GridView1.SelectedIndex returns -1 every time
its just not working
Vikas_Shukla_89 7-Oct-11 0:59am    
hi..
try this

int j = GridView1.SelectedRow.RowIndex;
_gCode = Convert.ToInt32(GridView1.DataKeys[j].Value);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900