dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] CheckBox not showing Checked on ASPX Page?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,832

    Resolved [RESOLVED] CheckBox not showing Checked on ASPX Page?

    I have a WebPage that contains a GridView. One of the columns contains an <asp:CheckBox> control. Since the control is within the Grid, I need to cast the control. So, I've created a variable as a CheckBox.

    Code:
        Private WithEvents CheckInspector As New CheckBox
    The Cast happens within a For Loop (looping through each row) in the PreRender Event where it calls a routine, "CastGridViewControls".

    Code:
        Protected Sub CastGridViewControls(gvr As GridViewRow)
                CheckInspector = DirectCast(gvr.FindControl("checkInspector"), CheckBox)
        End Sub
    So in the CheckInspector_Changed() Event, I have a statement (for debugging) that displays the value of the CheckBox. My problem is that when I check the box...it always shows as False and I cannot figure out what I'm doing wrong.

    Code:
        Protected Sub CheckInspector_Changed(sender As Object, e As System.EventArgs) Handles CheckInspector.CheckedChanged
            Dim gvr As GridViewRow = getActiveGridViewRow(sender)
    
            alert("CheckInspector.Checked = " & CheckInspector.Checked)
    
            If saveCompleted(gvr) Then
                BindTheGrid()
            End If
        End Sub
    Here is the markup in the HTML.

    Code:
    <asp:CheckBox ID="checkInspector" Enabled="true" AutoPostBack="true" OnCheckedChanged="CheckInspector_Changed" runat="server" />
    Any ideas???

    Thanks,
    Blake

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    399

    Re: CheckBox not showing Checked on ASPX Page?

    I'm not at all following the idea behind your CastGridView controls sub being called in a For loop. Since CheckInspector is a single checkbox object, I would assume that at the end of the for loop it is only set equal to the checkbox in the last row in your gridview and not at all connected to the checkbox in the rows above it.

    I'm also not following what this line is doing:

    Code:
    Dim gvr As GridViewRow = getActiveGridViewRow(sender)
    since you don't have the code for what getActiveGridViewRow does.

    Presumably all you should need to do is something like this (untested in a GridView setup but tested with multiple individual checkboxes that raise the same Changed event):

    Code:
    Protected Sub CheckInspector_Changed(sender As Object, e As System.EventArgs) Handles CheckInspector.CheckedChanged
    
            Dim gvr As GridViewRow = getActiveGridViewRow(sender)
    
            alert("CheckInspector.Checked = " & DirectCast(sender, Checkbox).Checked
    
            If saveCompleted(gvr) Then
                BindTheGrid()
            End If
    
        End Sub
    Edit to add: In the case of a checkbox column inside of a GridView row, I guess I'm not 100% sure what the "sender" object would be when the checkbox is clicked...I assume it is the checbox and not the entire GridViewRow, but even if it is the entire GridViewRow, you should be able access the checkbox object in the GridViewRow object from the CheckedChanged routine rather than the "pre-casting" that you seem to be doing now.
    Last edited by OptionBase1; Sep 4th, 2018 at 01:44 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,832

    Re: CheckBox not showing Checked on ASPX Page?

    Your code worked. All I needed to do was cast the checkbox in the CheckChanged event.

    Thank you!
    Blake

  4. #4
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    399

    Re: CheckBox not showing Checked on ASPX Page?

    Good to hear! I hope your job situation is going well.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,832

    Re: CheckBox not showing Checked on ASPX Page?

    So far so good! One day at a time.
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width