Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two bound fields and one check box in grid view . And the values in bound field comes from the table . Now i want to access the value of the autoid and store in it a session of the selected checkbox.
Posted

Hi,

I am not clear on your question. Do you want to keep primary key of the rows in the gridview? If so you can use a hidden field for this.
 
Share this answer
 
Comments
Vimalrashamra 7-Oct-11 1:06am    
I have a table which contains permissionid , userid , itemid and permissionstatus . And the values in that table comes from item table . Now i want that when a user selects any item through checkbox its permission staus become true . So for that i take the permission status as a checkbox and when user selects it i fire an update query on button click . But in that query i have to provide a condition that particular row is selected that's why i want the userid(primary key) from table . Please help
Use this

C#
GridView1.DataKeys[index].Value.ToString()


here index is row index of gridview

check this link

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx[^]

You can have multiple datakeys to access them see this link

DataKeyNames[^]
 
Share this answer
 
v2
Try this one:

C#
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
HiddenObjectID.Value = Convert.ToString(GvUserDetails.DataKeys[row.RowIndex].Value);
 
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