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

Populating GridClientSelectColumn based upon databound value

1 Answer 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cyd
Top achievements
Rank 1
Cyd asked on 23 Oct 2014, 07:20 PM
I have a grid that is displaying a couple of values from an object data source along with an unbound GridClientSelectColumn:

<Columns>
   <telerik:GridBoundColumn ColumnGroupName="gridData"
                                              DataField="LocationID"
                                              ReadOnly="true"
                                              UniqueName="LocationID">
   </telerik:GridBoundColumn>

   <telerik:GridBoundColumn ColumnGroupName="gridData"
                                              DataField="LocationDesc"
                                              ReadOnly="true"
                                              UniqueName="LocationDesc">
   </telerik:GridBoundColumn>

   <telerik:GridBoundColumn ColumnGroupName="gridData"
                                               DataField="DefaultValue"
                                               Display="false"
                                               UniqueName="DefaultValue">
   </telerik:GridBoundColumn>

   <telerik:GridClientSelectColumn ColumnGroupName="gridData" 
                                                        UniqueName="Select">
   </telerik:GridClientSelectColumn>

</Columns>

The LocationID, LocationDesc, and DefaultValues are coming from the datasource and are bound.  What I'd like to do is set that GridClientSelectColumn to selected if the DefaultValue (which is a Boolean) from the datasource is true.

I've tried several different approaches but have not found one that works yet.  Can anyone enlighten me?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 28 Oct 2014, 12:01 PM
Hi Cyd,

You can use the following approach to achieve the requested functionality:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        double value = 0;
        string data = DataBinder.Eval(item.DataItem, "Freight").ToString();
 
        if (double.TryParse(data, out value))
        {
            if (value > 5)
            {
                item.Selected = true;
            }
        }
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Cyd
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or