OnCheckedChanged事件不触发事件、OnCheckedChanged

由网友(别时泪)分享简介:我有一个复选框列(在GridView的其余部分被填充从数据库中)一个GridView。我使用AJAX来执行不同的功能,我想知道,如果我只是没有要求在正确的地方的OnCheckedChanged事件。如果它被包裹在某种的UpdatePanel?我还是很新的怎么所有这一切工作......基本上就是我的目标是改变位值在我的数...

我有一个复选框列(在GridView的其余部分被填充从数据库中)一个GridView。我使用AJAX来执行不同的功能,我想知道,如果我只是没有要求在正确的地方的OnCheckedChanged事件。如果它被包裹在某种的UpdatePanel?我还是很新的怎么所有这一切工作......基本上就是我的目标是改变位值在我的数据库中的复选框被选中时。我知道如何做到这一点的逻辑,我只是​​不知道如果我解决我的OnCheckedChanged事件的正确途径。

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

.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>

推荐答案

尝试在CheckBox控件转动的AutoPostBack。

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.

阅读全文

相关推荐

最新文章