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

Telerik Grid, GridClientSelectColumn bind data

2 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 16 Feb 2011, 04:07 PM
Hi Telerik Team,

I am working on the Telerik Grid, my first column in that grid is "GridClientSelectColumn", with which I am able to 'check' the required row and save to the database, but I could not bind the saved items to that "GridClientSelectColumn". Below is the sample code which I am using.

1. In Aspx Page

 

 

 

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true"

 

 

 

 

 

AllowAutomaticUpdates="True" PageSize="10" Width="100%" AutoGenerateColumns="false"

 

 

 

 

 

AllowMultiRowSelection="true" DataSourceID="sds_Reconcile" onitemcreated="RadGrid1_ItemCreated"

 

 

 

 

 

OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender">

 

 

 

 

 

 

<PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" />

 

 

 

 

 

<MasterTableView Name="Table1" DataKeyNames="id" AllowMultiColumnSorting="True" AllowFilteringByColumn="true" TableLayout="Fixed" EditMode="InPlace" CanRetrieveAllData="False">

 

 

 

 

 

 

<HeaderStyle CssClass="Level1HeaderStyle" />

 

 

 

 

 

<Columns>

 

 

 

 

 

<telerik:GridClientSelectColumn DataTextField="pvkey" Text="select" UniqueName="column1"

 

 

 

 

 

HeaderText="Select"> </telerik:GridClientSelectColumn>
...
</Columns>
2. C# Code
    a.  In ItemDataBound and ItemCreated i have used this code

 

 

 

 

        if (e.Item is GridDataItem)            {

 

 

 

 

 

            GridDataItem item = (GridDataItem)e.Item;

 

 

 

 

 

            if (item.OwnerTableView.Name == "Table")    {

 

 

 

 

 

                if (item["is_recon"].Text == "True") {

 

 

 

 

 

                    CheckBox chkbx = (CheckBox)item["column1"].Controls[0];

 

 

                            chkbx.Checked =

 

 

true;

 

 

                    e.Item.BackColor = System.Drawing.

 

 

ColorTranslator.FromHtml("green"); }}}

 

 

    b. In PreRender, I am using this code
        

 

 

            foreach

 

 

 

(GridDataItem dataItem in this.RadGrid1.MasterTableView.Items)

 

 

                    {

 

 

 

 

                        if (dataItem["is_recon"].Text == "True")

 

 

                    {

 

 

 

 

                        CheckBox chkbx = (CheckBox)dataItem["column1"].Controls[0];

 

 

                        chkbx.Checked =

 

 

true;

 

 

                        }

 

 

 

 

                    dataItem["column1"].BackColor = System.Drawing.Color.Gray;

 

 

 

 

 

 

 

 

 

                       }

 I am able to get the correct values from the database, and they are executing with the chkbx.Checked = true. But I could not see the items checked in the webpage when they are loaded.

And also I am using Default skin, and assigning my custom css to that Grid, with which I am unable to color the row. (dataItem["column1"].BackColor = System.Drawing.Color.Gray;)

Thanks
Mark

 

 

 

 

 

 

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2011, 06:36 AM
Hello Mark,
You can try selecting the row instead of checking the CheckBox explicitly.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
 {
     foreach(GridDataItem dataItem in this.RadGrid1.MasterTableView.Items)
     {
         if (dataItem["is_recon"].Text == "True")
         {
         dataItem.Selected = true;
         }
     }
 }

Thanks,
Shinu.
0
Mark
Top achievements
Rank 1
answered on 17 Feb 2011, 12:31 PM
Hi Shinu,

It worked fine by checking the condition and giving it as dataitem.selected = true;

Thanks
Mark
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or