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

Grid Client Select Column Select Checkbox from Server Side.

5 Answers 763 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sweta
Top achievements
Rank 1
sweta asked on 28 Oct 2010, 08:48 AM

Hi,

i'm using latest version of telerik.web.dll. we have used rad grid control in many of our pages. we have used GridClientSelect Column for the selection of rows. suppose i have parent page and child page. my child page contains radgrid( with GridclinetSelect Column).
i select some rows from child page and click the save button. my selected records are populated in my parent page. now i again open the child page. we want to show the user which rows the user has selected previously. but i'm not able to select the checkboxes from server side. is there anyother way so that i can display the selected rows again when i open the child page by displaying the selected checkboxes. i want to show the selected rows based on my datakey values.

please suggest some solution.

Thanks
Sweta

5 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 28 Oct 2010, 03:23 PM
Hello Sweta,

Please use the approach from the Client-Side Row Selection Persisted With Paging code library in order to implement the desired functionality.

I hope this helps.

Regards,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
zAxis
Top achievements
Rank 1
answered on 03 Apr 2012, 04:35 PM

You can check the GridClientSelectColumn from server-side like this.

Private Sub SelectGridRow()
   For Each dataItem As GridDataItem In rgRMR.MasterTableView.Items
      Dim vals As New Hashtable
      dataItem.ExtractValues(vals)
      If vals("RMRID") = r.RMRID Then
         Dim cb As CheckBox = CType(dataItem.FindControl("ClientSelectColumnSelectCheckBox"), CheckBox)
         cb.Checked = True
         dataItem.Selected = True
      End If
   Next
End Sub
0
Gaurav
Top achievements
Rank 1
answered on 26 Feb 2013, 12:08 PM
Dear All,

Please help me I am really struggling with accessing the GridClientSelectColumn at server side. My problem is as follows:

I have a RadGrid that has the following structure:

<Telerik:RadGrid ID="rgdPagePromotion" runat="server" AutoGenerateColumns="false"

 AllowAutomaticInserts="false" AllowMultiRowSelection="true" OnItemCreated="rgdPagePromotion_ItemCreated">

<PagerStyle Mode="NumericPages"></PagerStyle>

<MasterTableView AutoGenerateColumns="False" DataKeyNames="Publication">

  <Columns>

<Telerik:GridBoundColumn HeaderText="Publication Code" DataField="Publication"

                         ReadOnly="true" Visible="true" UniqueName="Publication Code" >

                        </Telerik:GridBoundColumn>

                                           

                        <Telerik:GridClientSelectColumn HeaderText="Promote" DataTextField="Promote" UniqueName="Promote"  >
     </Telerik:GridClientSelectColumn>

                        
                       <Telerik:GridImageColumn HeaderText="Status" ImageUrl=""

                        AlternateText="Not Yet started to Promote">

                       </Telerik:GridImageColumn>

       </Columns>

        </MasterTableView>

        
        <ClientSettings EnableRowHoverStyle="false" >

<Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true"></Selecting>

        </ClientSettings>

 </Telerik:RadGrid>


As you can see from above I am using a GridClientSelectColumn for having a checkbox column, with a header checkbox to select all checkboxes, in the radgrid. Now the problem is when the Radgrid is initially databinded on server side I wish to set some checkboxes. Then on the client side the user may make select/unselect the checkboxes. There is a separate button on the page on click of which, on postback, on server side again I need to access this GridClientSelectColumn to see which checkboxes are selected. 

I have read the article on 
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx

which describes something similar but they are using asp:checkboxes which I somehow do not wish to use due to some reason.  


On server side on page load immediately after 
            rgdPagePromotion.DataSource = dt;
            rgdPagePromotion.DataBind();

 I did try to access the column by the following code but it didn't work:

            foreach (GridDataItem item in rgdPagePromotion.MasterTableView.Items)
            {
                CheckBox cb = (CheckBox)item["Promote"].Controls[0];
                cb.Checked = true;
            }

The code shows no error but on client side the checkboxes are not checked. 

Could someone please help me with some code examples about how to access the gridClientSelectColumn checkboxes at server side during initial page load and then again on button click postback. 

Waiting eagerly for a response. 

Thanks and Regards,
Gaurav

0
Gaurav
Top achievements
Rank 1
answered on 26 Feb 2013, 12:17 PM
Dear All,

Please help me I am really struggling with accessing the GridClientSelectColumn at server side. My problem is as follows:

I have a RadGrid that has the following structure:

<Telerik:RadGrid ID="rgdPagePromotion" runat="server" AutoGenerateColumns="false"

 AllowAutomaticInserts="false" AllowMultiRowSelection="true"OnItemCreated="rgdPagePromotion_ItemCreated">

<PagerStyle Mode="NumericPages"></PagerStyle>

<MasterTableView AutoGenerateColumns="False" DataKeyNames="Publication">

  <Columns>

<Telerik:GridBoundColumn HeaderText="Publication Code"DataField="Publication"

                         ReadOnly="true" Visible="true" UniqueName="Publication Code" >

                        </Telerik:GridBoundColumn>

                                           

                        <Telerik:GridClientSelectColumn HeaderText="Promote"DataTextField="Promote" UniqueName="Promote"  >
     </Telerik:GridClientSelectColumn>

                        
                       <Telerik:GridImageColumn HeaderText="Status" ImageUrl=""

                        AlternateText="Not Yet started to Promote">

                       </Telerik:GridImageColumn>

       </Columns>

        </MasterTableView>

        
        <ClientSettings EnableRowHoverStyle="false" >

<Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true"></Selecting>

        </ClientSettings>

 </Telerik:RadGrid>


As you can see from above I am using a GridClientSelectColumn for having a checkbox column, with a header checkbox to select all checkboxes, in the radgrid. Now the problem is when the Radgrid is initially databinded on server side I wish to set some checkboxes. Then on the client side the user may make select/unselect the checkboxes. There is a separate button on the page on click of which, on postback, on server side again I need to access this GridClientSelectColumn to see which checkboxes are selected. 

I have read the article on 
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx

which describes something similar but they are using asp:checkboxes which I somehow do not wish to use due to some reason.  


On server side on page load immediately after 
            rgdPagePromotion.DataSource = dt;
            rgdPagePromotion.DataBind();

 I did try to access the column by the following code but it didn't work:

            foreach (GridDataItem item in rgdPagePromotion.MasterTableView.Items)
            {
                CheckBox cb = (CheckBox)item["Promote"].Controls[0];
                cb.Checked = true;
            }

The code shows no error but on client side the checkboxes are not checked. 

Could someone please help me with some code examples about how to access the gridClientSelectColumn checkboxes at server side during initial page load and then again on button click postback. 

Waiting eagerly for a response. 

Thanks and Regards,
Gaurav

0
Shinu
Top achievements
Rank 2
answered on 26 Feb 2013, 12:49 PM
Hi,

Please try the following code snippet to access the ClientSelectColumn in code behind.

For accessing the ClientSelectColumn in PageLoad and Checking them for the First time.
C#:
protected void rgdPagePromotion_PreRender(object sender, EventArgs e)
{
    // For Checking CheckBox Column for time first time on Pageload
    if (!IsPostBack)
    {
        foreach (GridDataItem item in rgdPagePromotion.MasterTableView.Items)
        {
            CheckBox cb = (CheckBox)item["Promote"].Controls[0];
            cb.Checked = true;
            item.Selected = true;
        }
    }
}

For accessing ClientSelectColumn and checking it on Button Click event.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in rgdPagePromotion.MasterTableView.Items)
    {
        CheckBox CheckBox1= (CheckBox)item["Promote"].Controls[0];
        CheckBox1.Checked = true;
        item.Selected = true;
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
sweta
Top achievements
Rank 1
Answers by
Mira
Telerik team
zAxis
Top achievements
Rank 1
Gaurav
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or