Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 2nd, 2007, 02:42 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Gridview checkbox problems

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
__________________
http://www.thewebsiteshop.co.uk
  #2 (permalink)  
Old May 3rd, 2007, 04:14 AM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default

Try putting gvUserList.DataBind() in Page_Load.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview and Checkbox krasnokojiy ASP.NET 2.0 Basics 14 February 28th, 2008 12:56 PM
Confirmation with checkbox in gridview collie Visual Studio 2005 0 October 24th, 2007 06:13 AM
Checkbox in Gridview yukijocelyn ASP.NET 2.0 Basics 0 September 24th, 2007 12:32 AM
GridView Checkbox ItemTemplate angelicagm ASP.NET 2.0 Professional 3 May 31st, 2007 04:44 AM
Checkbox in GridView aliirfan84 ASP.NET 2.0 Professional 1 May 15th, 2007 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.