Hello Ken,
You have correctly guessed that the server-side ItemDataBound event could be used for such requirement. In the ItemDataBound event handler you could get reference to the template column, then to the RadSlider control and finally, apply the customization:
And the code-behind:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable table =
new
DataTable();
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"RangeStart"
,
typeof
(
int
));
table.Columns.Add(
"RangeEnd"
,
typeof
(
int
));
table.Columns.Add(
"Color"
,
typeof
(
string
));
table.Rows.Add(1, 5, 10,
"#363636"
);
table.Rows.Add(2, 15, 20,
"#cc3636"
);
table.Rows.Add(3, 20, 30,
"#ff3636"
);
(sender
as
RadGrid).DataSource = table;
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
RadSlider slider = item[
"Slider"
].FindControl(
"RadSlider1"
)
as
RadSlider;
slider.BackColor = System.Drawing.ColorTranslator.FromHtml((item.DataItem
as
DataRowView).Row[
"Color"
].ToString());
}
}
Another approach is to handle this entirely in the markup:
Hope that helps.
Regards,
Konstantin Dikov
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.