Пример #1
0
        protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            var currentpage     = int.Parse(CurrentPageIndex.ToString());
            var currentpagesize = MainGridView.PageSize;
            //var totalnumofrows = MainGridView.Rows.Count;

            var floor = (currentpage * currentpagesize);
            var ceil  = ((currentpage * currentpagesize) + currentpagesize) - 1;

            //var sc = new StringCollection();
            //var id = string.Empty;

            var dt1 = new DataTable();

            var selectall  = SelectAllCheckBox;
            var chkchecked = selectall.Checked;

            if (!string.IsNullOrEmpty(SessionVariables.SortExpression) && !string.IsNullOrEmpty(SessionVariables.SortDirection))
            {
                skipgridreload = true;
                dt1            = SortGridView(SessionVariables.SortExpression, SessionVariables.SortDirection);
                skipgridreload = false;
            }
            else
            {
                dt1 = dtGlobal;
            }

            MainGridView.DataSource = dt1;
            MainGridView.DataBind();

            oGridPagiation = new GridPagiation();
            oGridPagiation.Setup(plcPaging, litPagingSummary, dt1, MainGridView, Page);
            oGridPagiation.Changed += oGridPagiation_Changed;
            oGridPagiation.ManagePaging(dt1);

            numberedPager.Setup(dt1.Rows.Count, MainGridView);
            numberedPager.Changed += oGridPagiation_Changed;

            ListHelper.AddCheckBox(MainGridView);

            SelectAllCheckBox.Checked = chkchecked;



            //loop the GridView Rows
            var j = 0;

            for (var i = floor; i <= ceil; i++)
            {
                if (j < MainGridView.Rows.Count)
                {
                    var cb = (CheckBox)MainGridView.Rows[j].Cells[0].FindControl("CheckBox1");                     //find the CheckBox

                    if (cb == null)
                    {
                        for (var k = 0; k < MainGridView.Rows[j].Cells[0].Controls.Count; k++)
                        {
                            if (MainGridView.Rows[j].Cells[0].Controls[k].ID.Equals("CheckBox1"))
                            {
                                cb = (CheckBox)MainGridView.Rows[j].Cells[0].Controls[k];
                            }
                        }
                    }

                    if (cb != null && SelectAllCheckBox != null)
                    {
                        if (SelectAllCheckBox.Checked)
                        {
                            if (!cb.Checked)
                            {
                                cb.Checked = true;                                 // add the id to be deleted in the StringCollection
                            }
                        }
                        else
                        {
                            if (cb.Checked)
                            {
                                cb.Checked = false;
                            }
                        }
                    }

                    j++;
                }
            }

            if (SelectAllCheckBox.Checked)
            {
                ButtonDelete.Enabled       = true;
                ButtonUpdate.Enabled       = true;
                ButtonDetails.Enabled      = true;
                ButtonCommonUpdate.Enabled = true;
                ButtonInlineUpdate.Enabled = true;

                ButtonDetails.Style.Add("background-color", "#B40404");
                ButtonDelete.Style.Add("background-color", "#B40404");
                ButtonUpdate.Style.Add("background-color", "#B40404");
                ButtonCommonUpdate.Style.Add("background-color", "#B40404");
                ButtonInlineUpdate.Style.Add("background-color", "#B40404");

                //ButtonDetails.Style.Add("display",""); //below 3 lines added to make the Delete, Details, Update buttons visible.
                //ButtonUpdate.Style.Add("display", "");
                //ButtonDelete.Style.Add("display", "");
            }
            else
            {
                ButtonDelete.Enabled       = false;
                ButtonUpdate.Enabled       = false;
                ButtonDetails.Enabled      = false;
                ButtonCommonUpdate.Enabled = false;
                ButtonInlineUpdate.Enabled = false;

                ButtonDetails.Style.Add("background-color", "#808080");
                ButtonDelete.Style.Add("background-color", "#808080");
                ButtonUpdate.Style.Add("background-color", "#808080");
                ButtonCommonUpdate.Style.Add("background-color", "#808080");
                ButtonInlineUpdate.Style.Add("background-color", "#808080");


                //ButtonDetails.Style.Add("display", "none");//below 3 lines added to make the Delete, Details, Update buttons invisible.
                //ButtonUpdate.Style.Add("display", "none");
                //ButtonDelete.Style.Add("display", "none");
            }
        }