Grid with checkbox

4 posts, 1 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 15 Mar 2011 Link to this post

    I am attempting to use a checkbox in a grid. I know there are many posts on this tompic but I just can't seem to get the checked values to work for me.

    Here is my code:

       Protected Sub btn_ModifyPerms_Click(sender As Object, e As System.EventArgs)
            For Each grdItem As GridDataItem In rgd_TaskPermissions.Items
                Dim cbx_Select As CheckBox = DirectCast(grdItem.FindControl("cbx_Select"), CheckBox)
                'Do Something   
                If cbx_Select.Checked = False Then
                    Session("PermSelect") = 0
                    Session("PermSelect") = 1
                End If
                Dim DatabaseName As String = Session("DBName")
                Dim Table As String = Session("Table")
                Dim TaskRole As String = Session("TaskRole")
                Dim connectionString = New SqlConnection("server=DO-IT-AB\MSSQLAB;database=AeriesAdmin;UID=itc.sysadmin;PWD=m1s.@dm1n6;")
                Dim command = New SqlCommand("aa_task_table_permissions_select", connectionString)
                command.CommandType = CommandType.StoredProcedure
                command.Parameters.Add("@dbname", SqlDbType.VarChar).Value = DatabaseName
                command.Parameters.Add("@Table", SqlDbType.VarChar).Value = Table
                command.Parameters.Add("@TaskRole", SqlDbType.VarChar).Value = Session("TaskRole")
                command.Parameters.Add("@PermSelect", SqlDbType.Int).Value = Session("PermSelect")
    End Sub

    The goal is for me to pass either a 1 or a 0 to a SQL Stored Procedure. I just can't seem to pass the correct parameter. I am not set on using a Session Variable. Any way I can get the 0 or the 1 to the @PermSelect variable is good by me.
  2. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 18 Mar 2011 Link to this post

    Resolved the issue.

    I needed to Qualify the binding of the data to the grid on pageload to ensure it was not on poast back.

    If Not Page.IsPostBack Then
        rgd_TaskPermissions.DataSource = GetPermissions()
    End If

    The issue occurs because I did not qualify the postback, the grid was only submitting the original data and not the data updated in the textboxes.
  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 18 Mar 2011 Link to this post

    Here is an example where I resolved the issue myself, but I cannot mark the post as answered because the poster cannot set their own response as the answer.
  5. Martin
    Martin avatar
    810 posts

    Posted 19 Mar 2011 Link to this post

    Hello Allan,

    Thank you for sharing your experience and code. I am sure it will be helpful for other members in our community.

    I have just marked your post as you have required.

    the Telerik team
Back to Top