代码不起作用...帮助 [英] code not working...help

查看:64
本文介绍了代码不起作用...帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在gridview中进行分页.我必须保存页眉checkbok的状态,如果在第一页中将其选中,则将自动检查每个页眉以及所有子复选框(在该列中).
请查看代码
在.aspx
中 -----

actually i''m doing paging in gridview. where i have to save state of header checkbok and if its selected in first page then automatically every page header will be checked as well as all child-checkboxes(in that column).
please review the code
in .aspx
-----

<head  runat="server">
    <title></title>
    <script src="Script/jquery-1.7.1.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            var headerCheckbox = $('#GridView1 > tbody > tr > th > input:checkbox');
            var childChkBoxes = $('#GridView1 > tbody > tr > td > input:checkbox');
            headerCheckbox.click(function () {
                $('input:checkbox:not(:disabled)').not('#GridView1 > tbody > tr > th > input:checkbox').click(function () {
                    if ($('input:checkbox:not(:disabled, :checked)').not('#GridView1 > tbody > tr > th > input:checkbox').length == 0)
                        $('#GridView1 > tbody > tr > th > input:checkbox').attr('checked', true)
                    else
                        headerCheckbox.attr('checked', false)
                }
      ).attr('checked', this.checked);
            })

            var state=<%Session["IS_CHECKED"].ToString();%>
            if(state!=null)
            {
            var headerCheckbox = $('#GridView1 > tbody > tr > th > input:checkbox');
            var childChkBoxes = $('#GridView1 > tbody > tr > td > input:checkbox');
            headerCheckbox.click(function () {
                $('input:checkbox:not(:disabled)').not('#GridView1 > tbody > tr > th > input:checkbox').click(function () {
                    if ($('input:checkbox:not(:disabled, :checked)').not('#GridView1 > tbody > tr > th > input:checkbox').length == 0)
                        $('#GridView1 > tbody > tr > th > input:checkbox').attr('checked', true)
                    else
                        headerCheckbox.attr('checked', false)
                }
      ).attr('checked', this.checked);
            })
            }

        });
        
    

        void PageIndexChanging(sender, eventArgs) {

            var headerCheckbox = $('#GridView1 > tbody > tr > th > input:checkbox');
            <%Session["IS_CHECKED"] = %> headerCheckbox.is(":checked");

        }

   </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

            PageSize="3" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"

            GridLines="None" DataSourceID="SqlDataSource1" OnPageIndexChanging="PageIndexChanging">
            <AlternatingRowStyle />
            <Columns>
                <asp:BoundField DataField="OrderId" HeaderText="OrderId" SortExpression="OrderId" />
                <asp:BoundField DataField="OrderName" HeaderText="OrderName" SortExpression="OrderName" />
                <asp:BoundField DataField="Availability" HeaderText="Availability" SortExpression="Availability" />
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:CheckBox ID="checkAllRecords" runat="server" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkRow" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

            SelectCommand="SELECT * FROM [OrderTable]"></asp:SqlDataSource>
    </div>
    </form>
</body>



和CB文件.cs
----



and CB file .cs
----

protected void Page_Load(object sender, EventArgs e)
       {
           Session["IS_CHECKED"] = null;
       }

推荐答案

(文档).ready( var headerCheckbox =
(document).ready(function () { var headerCheckbox =


(' var childChkBoxes =
('#GridView1 > tbody > tr > th > input:checkbox'); var childChkBoxes =


(' 函数(){
('#GridView1 > tbody > tr > td > input:checkbox'); headerCheckbox.click(function () {


这篇关于代码不起作用...帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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