OnCheckedChanged event not firing
Asked Answered
G

2

34

I have a GridView with a column of checkboxes (the rest of the GridView is being populated from a database). I'm using AJAX to perform different functions, and I'm wondering if i'm just not calling the OnCheckedChanged event in the right place. Should it be wrapped in some sort of UpdatePanel? I'm still really new to how all of this works...basically what I'm aiming for is to change a bit value in my database when a checkbox is checked. I know the logic of how to do that, I just don't know if I'm addressing my OnCheckedChanged event the right way.

.CS

        protected void CheckBoxProcess_OnCheckedChanged(Object sender, EventArgs args)
    {
        CheckBox checkbox = (CheckBox)sender;
        GridViewRow row = (GridViewRow)checkbox.NamingContainer;
        OrderBrowser.Text += "CHANGED";
    }


    }

.aspx

<html xmlns="http://www.w3.org/1999/xhtml">

        <asp:DropDownList runat="server" ID="orderByList" AutoPostBack="true">
            <asp:ListItem Value="fName" Selected="True">First Name</asp:ListItem>
            <asp:ListItem Value="lName">Last Name</asp:ListItem>
            <asp:ListItem Value="state">State</asp:ListItem>
            <asp:ListItem Value="zip">Zip Code</asp:ListItem>
            <asp:ListItem Value="cwaSource">Source</asp:ListItem>
            <asp:ListItem Value="cwaJoined">Date Joined</asp:ListItem>
        </asp:DropDownList>
    </div>
    <div>
        <asp:Label runat="server" ID="searchLabel" Text="Search For: " />
        <asp:TextBox ID="searchTextBox" runat="server" Columns="30" />
        <asp:Button ID="searchButton" runat="server" Text="Search" />
    </div>
<div>
<asp:UpdatePanel ID = "up" runat="server">
<Triggers>
    <asp:AsyncPostBackTrigger ControlID = "orderByList"
    EventName="SelectedIndexChanged" />
     <asp:AsyncPostBackTrigger ControlId="searchButton" EventName="Click" />
</Triggers>

<ContentTemplate>
<div align="center">
    <asp:GridView ID="DefaultGrid" runat = "server" DataKeyNames = "fName"
    onselectedindexchanged = "DefaultGrid_SelectedIndexChanged"
    autogenerateselectbutton = "true" 
    selectedindex="0">
    <SelectedRowStyle BackColor="Azure"
    forecolor="Black"
    font-bold="true" />
    <Columns>
    <asp:TemplateField HeaderText="Processed">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBoxProcess" runat="server" Enabled="true" OnCheckedChanged = "CheckBoxProcess_OnCheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>

    </Columns>
    </asp:GridView>
    </div>
    <asp:TextBox ID="OrderBrowser" columns="100" Rows="14" runat="server" Wrap="false" TextMode="MultiLine" ReadOnly = "true">
    </asp:TextBox>
    </ContentTemplate>
    </asp:UpdatePanel>



</div>
</form>

Galina answered 6/7, 2011 at 13:0 Comment(0)
P
79

Try turning AutoPostBack on for the checkbox control.

<asp:CheckBox ID="CheckBoxProcess" runat="server" Enabled="true" OnCheckedChanged = "CheckBoxProcess_OnCheckedChanged" AutoPostBack="true" />

This maybe the reason your method isn't being called.

Polymerous answered 6/7, 2011 at 13:5 Comment(3)
When I do this the check appears for like 2 seconds, and then disappears. Could it just be that way because I'm not handling anything in the database? I want it to be when there is a certain value in the DB, the check either appears or disappears. However, my test code isn't showing that the method is being called either...Galina
Possibly, it is worth entering some dummy data just to check the functionality.Polymerous
I was testing it, and the test wasn't showing anything at all :(Galina
R
-2

Please try to check the value with the DB:

Checked='<%# Convert.ToBoolean(Eval("Processed")) %>'

Ribbon answered 6/7, 2012 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.