Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I have a gridview with 2 data key names like DataKeyNames="targetid,RequestID" and now I want get their value in my C#.

When I write gv.SelectedValue just I have a first datakeys value or when I write gv.datakeys[0].value just I have the value of first rows and first datakeys.

I don't know how can I get the value of secend datakeys value. Help me.
Posted
Updated 5-Sep-11 18:30pm
v2

You can use DataKey.Values[^]
C#
gvMyGridView.DataKeys[gv.RowIndex].Values["targetid"]
gvMyGridView.DataKeys[gv.RowIndex].Values["RequestID"]
 
Share this answer
 
If you have DataKeysNames like
DataKeyNames="targetid,RequestID"

You can access them as
C#
string targetID= gv.DataKeys[e.RowIndex].Values[0].ToString();
string requestID= gv.DataKeys[e.RowIndex].Values[1].ToString();

Or you can use as below as well,
SQL
gv.DataKeys[e.SelectedIndex].Values["targetid"];
gv.DataKeys[e.SelectedIndex].Values["RequestID"];

Hope this answers your questions.
 
Share this answer
 

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