This is a migrated thread and some comments may be shown as answers.

Checkbox in Radgrid.

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erin
Top achievements
Rank 1
Erin asked on 10 Sep 2013, 01:41 PM
Hi..
I am using GridClientSelectColumn, but the checkbox values doesn't persist when paging..
Please can you show how to make the checkbox to be in checked state after paging. I want to access the rows in a button click..

Thanks,
Erin

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 10 Sep 2013, 01:49 PM
Hi Erin,

Please try the following code snippet to access checked rows on button click.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  . . . .>
    <MasterTableView  DataKeyNames="CustomerID" >
        <Columns>
          <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
        </Columns>
    </MasterTableView>      
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

C#:
ArrayList selectedItems;
  
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {     
        if (Session["selectedItems"] == null)
        {
            selectedItems = new ArrayList();
        }
        else
        {
            selectedItems = (ArrayList)Session["selectedItems"];
        }
        if (e.CommandName == "RowClick")
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            string customerID = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["CustomerID"].ToString();
            if (dataItem.Selected)
            {
                selectedItems.Add(customerID);
                Session["selectedItems"] = selectedItems;
            }
            else
            {
                selectedItems.Remove(customerID);
                Session["selectedItems"] = selectedItems;
            }
        }      
    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (Session["selectedItems"] != null)
        {
            ArrayList selectedItems = (ArrayList)Session["selectedItems"];
            Int16 stackIndex;
            for (stackIndex = 0; stackIndex <= selectedItems.Count - 1; stackIndex++)
            {
                string curItem = selectedItems[stackIndex].ToString();
                foreach (GridItem item in RadGrid1.MasterTableView.Items)
                {
                    if (item is GridDataItem)
                    {
                        GridDataItem dataItem = (GridDataItem)item;
                        if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["CustomerID"].ToString()))
                        {
                            dataItem.Selected = true;
                            break;
                        }
                    }
                }
            }
        }
    }
   
protected void Button1_Click(object sender, EventArgs e)
{
    if (Session["selectedItems"] != null)
    {
        ArrayList selectedItems = (ArrayList)Session["selectedItems"];
        Int16 stackIndex;
        for (stackIndex = 0; stackIndex <= selectedItems.Count - 1; stackIndex++)
        {
            RadGrid1.AllowPaging = false;
            RadGrid1.Rebind();
            string curItem = selectedItems[stackIndex].ToString();
            foreach (GridItem item in RadGrid1.MasterTableView.Items)
            {
                if (item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)item;
                    if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["CustomerID"].ToString()))
                    {
                            
                        dataItem.Selected = true;
                        Response.Write(curItem);//Datakey value of the selcted items
                        Response.Write("<br/>");
                        break;
                    }
                }
            }
        }         
    }
    RadGrid1.AllowPaging = true;
    RadGrid1.Rebind();      
    }

Thanks,
Princy
Tags
Grid
Asked by
Erin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or