Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview checkbox problems

Gridview checkbox problems

Scheduled Pinned Locked Moved ASP.NET
questiondatabasewpfwcfdesign
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pauliehaha
    wrote on last edited by
    #1

    Hi, I have a gridview with a few bound fields and 2 checkboxes in template fields. I have some filter fields which go in a placeholder on the page e.g. Disabled and Deleted checkboxes When the user initially enters the stored procedure executes and returns the complete list. When a user checks disabled in the filter and hits submit the page reloads executes the stored procedure and returns the items that are disabled. My binding code is as follows: daUserList.Fill(dtUserList) gvUserList.DataSource = dtUserList gvUserList.DataBind() Protected Sub gvUserList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvUserList.RowDataBound Dim chkDisabled As CheckBox = CType(e.Row.FindControl("disabled"), CheckBox) Dim chkDeleted As CheckBox = CType(e.Row.FindControl("deleted"), CheckBox) Dim dataRow As DataRowView = e.Row.DataItem If dataRow IsNot Nothing Then chkDisabled.Checked = dataRow.Item("disabled") chkDeleted.Checked = dataRow.Item("deleted") End If End Sub Now when the page first loads the checkboxes are populated correctly but when I submit filter options the page reloads with the new results but with checkbox values appearing as they did in the previous view. I've set EnableViewState="false" on the form, the gridview and the checkboxes but no joy. Also when I debug the checkboxes are being set correctly so it must be something that is happening after the RowDataBound event that is resetting the new checkboxes with values from the checkboxes in the previous full list. This is so frustrating, it's the last issue in my project, I've already spent a day on it and it's starting to make my project overrun! Please, can anyone shed any light on what is happening before I start going grey? Many Thanks, Paul The Website Shop

    S R 2 Replies Last reply
    0
    • P pauliehaha

      Hi, I have a gridview with a few bound fields and 2 checkboxes in template fields. I have some filter fields which go in a placeholder on the page e.g. Disabled and Deleted checkboxes When the user initially enters the stored procedure executes and returns the complete list. When a user checks disabled in the filter and hits submit the page reloads executes the stored procedure and returns the items that are disabled. My binding code is as follows: daUserList.Fill(dtUserList) gvUserList.DataSource = dtUserList gvUserList.DataBind() Protected Sub gvUserList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvUserList.RowDataBound Dim chkDisabled As CheckBox = CType(e.Row.FindControl("disabled"), CheckBox) Dim chkDeleted As CheckBox = CType(e.Row.FindControl("deleted"), CheckBox) Dim dataRow As DataRowView = e.Row.DataItem If dataRow IsNot Nothing Then chkDisabled.Checked = dataRow.Item("disabled") chkDeleted.Checked = dataRow.Item("deleted") End If End Sub Now when the page first loads the checkboxes are populated correctly but when I submit filter options the page reloads with the new results but with checkbox values appearing as they did in the previous view. I've set EnableViewState="false" on the form, the gridview and the checkboxes but no joy. Also when I debug the checkboxes are being set correctly so it must be something that is happening after the RowDataBound event that is resetting the new checkboxes with values from the checkboxes in the previous full list. This is so frustrating, it's the last issue in my project, I've already spent a day on it and it's starting to make my project overrun! Please, can anyone shed any light on what is happening before I start going grey? Many Thanks, Paul The Website Shop

      S Offline
      S Offline
      Senseicads
      wrote on last edited by
      #2

      I don't know if this will help you at all, and bear with me as I am very much a beginner, but I am using a checkbox field in my gridview as well, however I didn't create it the way you have I used an Item Template and whacked in the checkbox on the page there, something like this the active field that i am binding on is a simple int field in the database with either 0 for unchecked and -1 (although i believe and int will do cept 0)for checked. Dunno if that helps you out any? Cheers Ian Caddick

      P 1 Reply Last reply
      0
      • P pauliehaha

        Hi, I have a gridview with a few bound fields and 2 checkboxes in template fields. I have some filter fields which go in a placeholder on the page e.g. Disabled and Deleted checkboxes When the user initially enters the stored procedure executes and returns the complete list. When a user checks disabled in the filter and hits submit the page reloads executes the stored procedure and returns the items that are disabled. My binding code is as follows: daUserList.Fill(dtUserList) gvUserList.DataSource = dtUserList gvUserList.DataBind() Protected Sub gvUserList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvUserList.RowDataBound Dim chkDisabled As CheckBox = CType(e.Row.FindControl("disabled"), CheckBox) Dim chkDeleted As CheckBox = CType(e.Row.FindControl("deleted"), CheckBox) Dim dataRow As DataRowView = e.Row.DataItem If dataRow IsNot Nothing Then chkDisabled.Checked = dataRow.Item("disabled") chkDeleted.Checked = dataRow.Item("deleted") End If End Sub Now when the page first loads the checkboxes are populated correctly but when I submit filter options the page reloads with the new results but with checkbox values appearing as they did in the previous view. I've set EnableViewState="false" on the form, the gridview and the checkboxes but no joy. Also when I debug the checkboxes are being set correctly so it must be something that is happening after the RowDataBound event that is resetting the new checkboxes with values from the checkboxes in the previous full list. This is so frustrating, it's the last issue in my project, I've already spent a day on it and it's starting to make my project overrun! Please, can anyone shed any light on what is happening before I start going grey? Many Thanks, Paul The Website Shop

        R Offline
        R Offline
        RSArockiam
        wrote on last edited by
        #3

        Check, r u updating the data before populating (loading) again?

        Regards R.Arockiapathinathan

        P 1 Reply Last reply
        0
        • S Senseicads

          I don't know if this will help you at all, and bear with me as I am very much a beginner, but I am using a checkbox field in my gridview as well, however I didn't create it the way you have I used an Item Template and whacked in the checkbox on the page there, something like this the active field that i am binding on is a simple int field in the database with either 0 for unchecked and -1 (although i believe and int will do cept 0)for checked. Dunno if that helps you out any? Cheers Ian Caddick

          P Offline
          P Offline
          pauliehaha
          wrote on last edited by
          #4

          Hi, Thanks that's what I have

          1 Reply Last reply
          0
          • R RSArockiam

            Check, r u updating the data before populating (loading) again?

            Regards R.Arockiapathinathan

            P Offline
            P Offline
            pauliehaha
            wrote on last edited by
            #5

            No, I am simply reloading the page, executing the stored procedure to return a subset of the original view and then databinding those results to the gridview. I use the gvUserList_RowDataBound event to tie up the checkboxes after the bind but even though it seems to all happen correctly in debug when my page is redisplayed it looks as though the checkboxes have picked up the values from the previous view, even though I have Enableviewstate="false" in the page directive, on the form, gridview, and controls themselves. Any idea what is happening?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups