Hi,
I have a gridview with bound fields and 2 checkboxes in template fields:
Code:
<form id="formUser" enableviewstate="false" runat="server">
<asp:Literal ID="lblText" runat="server" />
<div class="yellowbox mid center" id="UserFilter" runat="server" visible="false">
<div class="centertext" id="UserFilterLinks" runat="server">
[list]
<li><asp:HyperLink ID="CancelLink" runat="server" /></li>
<li><asp:HyperLink ID="AddLink" runat="server" /></li>
<li><asp:HyperLink ID="OptLink" runat="server" /></li>
<li><asp:HyperLink ID="RefreshLink" runat="server" Visible="false" /></li>
</ul>
</div>
<fieldset id="UserFilterOptions" runat="server" visible="false">
<legend id="UserFilterOptionsLegend" runat="server" />
<asp:PlaceHolder ID="phUserFilter" runat="server" />
</fieldset>
</div>
<asp:GridView AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Cssclass="mid center"
EmptyDataText="No records returned" EnableViewState="false" GridLines="None" ID="gvUserList" PagerSettings-Mode="NumericFirstLast"
OnPageIndexChanging = "gvwCalls_PageIndexChanging" OnSorting="gvwCalls_Sorting" runat="server">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="name" HeaderText="name" ReadOnly="True" SortExpression="name" />
<asp:BoundField DataField="email" HeaderText="email" ReadOnly="True" SortExpression="email" />
<asp:BoundField DataField="userlogin" HeaderText="userlogin" ReadOnly="True" SortExpression="userlogin" />
<asp:BoundField DataField="lastloggedin" HeaderText="lastloggedin" ReadOnly="True" SortExpression="lastloggedin" />
<asp:BoundField DataField="loginattempts" HeaderText="loginattempts" ReadOnly="True" SortExpression="loginattempts" >
<ItemStyle CssClass="centertext" />
</asp:BoundField>
<asp:TemplateField ItemStyle-CssClass="centertext" HeaderText="disabled" SortExpression="disabled">
<ItemTemplate>
<asp:CheckBox EnableViewState="false" ID="disabled" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="centertext" HeaderText="deleted" SortExpression="deleted">
<ItemTemplate>
<asp:CheckBox EnableViewState="false" ID="deleted" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
<asp:PlaceHolder ID="phUserDetails" runat="server">
<div class="bluebox mid center" id="User">
<div class="pad">
<asp:PlaceHolder ID="phUserControls" runat="server" />
</div>
</div>
</asp:PlaceHolder>
</form>
There are some filter fields which go in the phUserFilter placeholder e.g. Disabled and Deleted checkboxes
When the user initially enters the stored procedure executes and returns the complete user list.
When a user checks disabled in the filter and hits submit the page reloads executes the stored procedure and returns all users that are disabled.
My binding code is as follows:
Code:
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
http://www.thewebsiteshop.co.uk