Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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;

                    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!
Updated 22-Mar-12 6:18am
phil.o 22-Mar-12 7:10am    

Is it a joke ?
You convert an int to a string, and then use int.Parse() to get the original int again ?
visnumca123 22-Mar-12 9:46am    
please take a look now!
ZurdoDev 22-Mar-12 8:11am    
The message is about JavaScript. Where is your JavaScript code?
visnumca123 22-Mar-12 8:17am    
on the click event i'm using this event and functions only not javascript!
ZurdoDev 22-Mar-12 12:54pm    
But the message is that a script is causing it to run slow so there is some script somewhere. How are you invoking the C#?

1 solution

Hi ,
this example will Guide you .

<html xmlns="">
<head runat="server">

    <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;
    <form id="form1" runat="server">
    <asp:GridView ID="Gridview1" runat="server"
                    OnRowDataBound="Gridview1_RowDataBound" AllowPaging="True"

                                    <asp:CheckBox ID="Chk" runat="server" />
                                    <asp:CheckBox ID="Chk1" runat="server" />

                            <asp:TemplateField HeaderText="test">
                                    <asp:Label ID="lbl_Val" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                      <asp:HiddenField ID="HF2" runat="server" />

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 { };
        Gridview1.DataSource = result;

    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
                "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("Chk1")).ClientID + "')");
        else if ((e.Row.RowType == DataControlRowType.DataRow))
                "javascript:unCheck('" + HF2.Value + "','" + ((CheckBox)e.Row.FindControl("Chk")).ClientID + "')");


Share this answer
Mohamed Mitwalli 23-Mar-12 16:22pm    
was it useful ..??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900