OnCheckedChanged事件不触发 [英] OnCheckedChanged event not firing

查看:1574
本文介绍了OnCheckedChanged事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列(在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.

这篇关于OnCheckedChanged事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆