Gridview checkbox problems
-
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 -
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 ShopI 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
-
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 ShopCheck, r u updating the data before populating (loading) again?
Regards R.Arockiapathinathan
-
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
Hi, Thanks that's what I have
-
Check, r u updating the data before populating (loading) again?
Regards R.Arockiapathinathan
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?