Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 30, 2012 02:53 PM by daveharney
Apr 30, 2012 02:53 PM|LINK
I had a lot of trouble figuring out how to determine if a checkbox (for a selected row) in a gridview was checked or not. Most of the examples were in C# or dealt with iterating through the entire grid. For those with a similar problem, here is what worked
In the markup
<asp:CheckBoxField DataField="Ready" HeaderText="Ready" ReadOnly="True" SortExpression="Ready" />
<asp:ButtonField ButtonType="Link" HeaderText="Detail Page" DataTextField="DetailPage"
SortExpression="DetailPage" CommandName="SelectRow" >
the user clicks the "button" in the last column to get more info. However, I needed to check the "Ready"
checkbox to see if that page is actually ready to be viewed. I know that I should just disable the link in the markup if the checkbox is not checked (some other issues with that yet). But, perhaps this code is useful to someone for understanding how to get at a check in a gridview in VB - it was painful for me!
Partial Class Routes
Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "SelectRow" Then
Dim sometext As String
Dim routeReady As CheckBox
Dim DetailPage As String
GridView1.SelectedIndex = Convert.ToInt16(e.CommandArgument)
sometext = Convert.ToString(GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text)
routeReady = GridView1.Rows(GridView1.SelectedIndex).Cells(9).Controls(0)
Check the ready box which is in cell 9
If routeReady.Checked Then
DetailPage = "~/RouteDetails/route" + sometext + ".aspx"