This is a migrated thread and some comments may be shown as answers.

Grid with checkbox

3 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 16 Mar 2011, 12:27 AM
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
            Else
                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")
  
            command.Connection.Open()
            command.ExecuteNonQuery()
            command.Connection.Close()
  
  
  
        Next
  
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.

3 Answers, 1 is accepted

Sort by
0
Allan
Top achievements
Rank 2
answered on 18 Mar 2011, 08:35 PM
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()
    rgd_TaskPermissions.DataBind()
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.
0
Accepted
Allan
Top achievements
Rank 2
answered on 18 Mar 2011, 08:37 PM
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.
0
Martin
Telerik team
answered on 19 Mar 2011, 09:09 AM
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.

Regards,
Martin
the Telerik team
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Allan
Top achievements
Rank 2
Martin
Telerik team
Share this question
or