Question : How to reference the "checked" value of a checkbox in a GridView template field

In my GridView control, I have a template field that contains a checkbox.  My user can check and/or uncheck the checkbox and then click a buttonfield on the same row to fire the GridView's RowCommand event procedure.

In my event procedure, I need to pass off the "checked" value of the checkbox in the selected row but can't figure out how to do that.  Can anyone help?  Thanks!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:

	
		
		
		
		
			
				
			
		
		
	


Protected Sub gvSubscriptionsAvailable_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvSubscriptionsAvailable.RowCommand
	With Me
		Dim blnAutoRenew As Boolean

		If e.CommandName = "Select" Then
			For i = 0 To Me.lstModuleSelect.Items.Count - 1
				If .lstModuleSelect.Items(i).Selected Then
					blnAutoRenew = .gvSubscriptionsAvailable.SelectedRow... 
				End If
			Next
		End If
	End With
End Sub

Answer : How to reference the "checked" value of a checkbox in a GridView template field

since you are having your button command="Select" you can use SelectedIndexChanged event instead like below:

Protected Sub gvSubscriptionsAvailable_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim blnAutoRenew As Boolean
    Dim chb As CheckBox = DirectCast(gvSubscriptionsAvailable.SelectedRow.FindControl("chkAutoRenew"), CheckBox)
    If chb IsNot Nothing Then
        blnAutoRenew = chb.Checked
    End If
End Sub

The main idea is to get the row and findControl for the checkbox.
Random Solutions  
 
programming4us programming4us