.net网格中的脚本运行缓慢错误 [英] script running slow error in .net grid checked

查看:60
本文介绍了.net网格中的脚本运行缓慢错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,


我在网格复选框上有一个问题,如果我只有10行,则意味着它会立即进行检查,但是如果行数上升到200或300行,则意味着会出现弹出错误os停止运行脚本?此页面上的脚本导致运行缓慢. br/> 我的循环代码是:

Hi Friends,


I have a issue on grid checkbox if i had only 10 rows means its immediately checking but if the rows went up to 200 or 300 rows means raising popup error os stop running script?A script on this page is causing ie to run slow.
my code for loop is:

int intRecIndex = 1;

            foreach (GridViewRow row in CGridView1.Rows)
            {

                chk = (CheckBox)row.FindControl("chkSelect");
                sel = (CheckBox)row.FindControl("chkSelect");

                if (intRecIndex <= CGridView1.Rows.Count)
                {
                    chk.Checked = true;
                    intRecIndex++;
                    checkall();

                }
                else
                {
                    chk.Checked = false;

                }
            }

 public void checkall()
    {

        sel.Checked = true;
        //CheckBox SelectedCheckBox = (CheckBox)sender;
        GridViewRow SelectedGridRow = (GridViewRow)sel.NamingContainer;
        CheckBox rb = (CheckBox)SelectedGridRow.FindControl("chkSelect");
        TextBox ddlgrpcode1 = (TextBox)SelectedGridRow.FindControl("CA_Reason_Desc3");
        ddlgrpcode1.Enabled = true;

    }



请帮我解决这个问题!



please help me how to resolve this!

推荐答案


这个例子将指导您.

Hi ,
this example will Guide you .

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">
        function SelectAll(id) {
            var frm = document.forms[0];

            for (i = 0; i < frm.elements.length; i++) {

                if (frm.elements[i].type == "checkbox") {

                    if (frm.elements[i].disabled == true) {

                        frm.elements[i].checked = false;

                    }

                    else {

                        frm.elements[i].checked = document.getElementById(id).checked;

                    }

                }

            }

        }

        function unCheck(id) {

            var frm = document.forms[0];

            var paren = document.getElementById(id);

            var flag = true;

            for (i = 0; i < frm.elements.length; i++) {

                if (frm.elements[i].type == "checkbox") {

                    if (!frm.elements[i].checked) {

                        paren.checked = false;

                        if (frm.elements[i] != paren)

                            flag = false;

                    }

                }

            }

            if (flag == true) paren.checked = true;

        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="Gridview1" runat="server"

                        AutoGenerateColumns="False"

                    OnRowDataBound="Gridview1_RowDataBound" AllowPaging="True"



                        >
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="Chk" runat="server" />
                                </ItemTemplate>
                                <HeaderTemplate>
                                    <asp:CheckBox ID="Chk1" runat="server" />
                                </HeaderTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="test">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_Val" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                      <asp:HiddenField ID="HF2" runat="server" />
    </div>
    </form>
</body>
</html>


public partial class _Default : System.Web.UI.Page
{
    testDataContext db = new testDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        //binding to Grid
        var result = from x in db.tests
                     select new { x.name };
        Gridview1.DataSource = result;
        Gridview1.DataBind();

    }
    protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if ((e.Row.RowType == DataControlRowType.Header))
        {
            HF2.Value = ((CheckBox)e.Row.FindControl("Chk1")).ClientID;
            //adding an attribut for onclick event on the check box in the hearder and passing the ClientID of the Select All checkbox
            ((CheckBox)e.Row.FindControl("Chk1")).Attributes.Add("onclick",
                "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("Chk1")).ClientID + "')");
        }
        else if ((e.Row.RowType == DataControlRowType.DataRow))
        {
            ((CheckBox)e.Row.FindControl("Chk")).Attributes.Add("onclick",
                "javascript:unCheck('" + HF2.Value + "','" + ((CheckBox)e.Row.FindControl("Chk")).ClientID + "')");

        }

    }


这篇关于.net网格中的脚本运行缓慢错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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