Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.
Using  Rad Grid

/// <summary>
    /// Rows Check box check event.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void chkItemChecked_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            ((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
            AssignedHeaderCheckBoxState((sender as CheckBox).Checked);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    /// <summary>
    /// Header check box click event select/Unselect all rows.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void chkAllItems_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            if ((sender as CheckBox).Checked)
            {
                foreach (GridDataItem dataItem in RadGridCoverageAreaStates.MasterTableView.Items)
                {
                    (dataItem.FindControl("chkItemChecked") as CheckBox).Checked = true;
                    dataItem.Selected = true;
                }
            }
            else
            {
                foreach (GridDataItem dataItem in RadGridCoverageAreaStates.MasterTableView.Items)
                {
                    (dataItem.FindControl("chkItemChecked") as CheckBox).Checked = false;
                    dataItem.Selected = false;
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
______________________
 /// <summary>
    /// Check/Uncheck Header Check Box on the basis of all rows Selection/UnSelection.
    /// </summary>
    /// <param name="bChecked"></param>
    private void AssignedHeaderCheckBoxState(bool bChecked)
    {
        int iCounter = 0;
        DataTable dtCityList = ((DataSet)ViewState["ProductCovarageAreaStates"]).Tables[0]; ;
        foreach (GridDataItem gdItem in RadGridCoverageAreaStates.Items)
            if ((gdItem.FindControl("chkItemChecked") as CheckBox).Checked == bChecked)
                iCounter++;
        if (dtCityList != null)
        {
            if (iCounter == dtCityList.Rows.Count)
            {
                foreach (GridHeaderItem HeaderItem in RadGridCoverageAreaStates.MasterTableView.GetItems(GridItemType.Header))
                {
                    ((CheckBox)(HeaderItem.FindControl("chkAllItems"))).Checked = bChecked;
                    break;
                }
            }
            else
            {
                foreach (GridHeaderItem HeaderItem in RadGridCoverageAreaStates.MasterTableView.GetItems(GridItemType.Header))
                {
                    ((CheckBox)(HeaderItem.FindControl("chkAllItems"))).Checked = false;
                    break;
                }
            }

        }
    } Posted on Thursday, April 3, 2008 7:01 PM Vini | Back to top


Comments on this post: Check All Functionality in Grid

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Taneja | Powered by: GeeksWithBlogs.net