Question : Assign DataKeyNames value for selected row in GridView to variable of Byte datatype

Hi Experts.  I hope this will be an easy question for someone to answer - I've tried finding my own answer but can't seem to find a solution that matches my exact problem.

My page contains a GridView control with numerous products displayed.  The DataKeyNames property for this GridView is "ID".  The ID column is NOT displayed (or even included) in the grid.  On each row of the grid there is an "AddToCart" button which with a CommandName property of "Select".  When the user clicks this button, I want the selected item to be added to the shopping cart.  In order to do this, I need to reference (in my VB Code) the DataKeyNames value for the selected row, convert it from a string to a Byte datatype, and assign it to a variable "bytModuleID".  Can anyone help me figure out how this is done?  Thanks!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
----HTML----

	
		
		
	


----VB.NET CODE-BEHIND----
Protected Sub gvSubscriptionsAvailable_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvSubscriptionsAvailable.SelectedIndexChanged
	Dim bytModuleID As Byte = 
	
	
End Sub

Answer : Assign DataKeyNames value for selected row in GridView to variable of Byte datatype

Use SelectedIndexChanged Event and you can get the datakey like below:

Dim bytModuleID As [Byte] = Convert.ToByte(gvSubscriptionsAvailable.DataKeys(SelectedIndex).Value)
Random Solutions  
 
programming4us programming4us