Hi Telerik
How can I change dynamically ItemStyle.Font.Bold of
I am trying with this code but does not work ?
How can I change dynamically ItemStyle.Font.Bold of
GridBoundColumn
I am trying with this code but does not work ?
GridBoundColumn
gc = RadGridDocument.MasterTableView.Columns.FindByUniqueName("Index") as GridBoundColumn;
foreach (var item in Items)
{
if (item.ParentID > 0)
gc.ItemStyle.Font.Bold =
true;
else
gc.ItemStyle.Font.Bold =
false;
}
7 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Mar 2012, 10:21 AM
Hello,
Thanks,
Jayesh Goyani
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) { item["Index"].ForeColor = System.Drawing.Color.Red; }Thanks,
Jayesh Goyani
0
Shinu
Top achievements
Rank 2
answered on 21 Mar 2012, 10:21 AM
Hello,
Try accessing the BoundColumn in ItemDataBound event as shown below.
C#:
Thanks,
Shinu.
Try accessing the BoundColumn in ItemDataBound event as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridDataItem) { GridDataItem itm = (GridDataItem)e.Item; TableCell cell = (TableCell)itm["Index"]; cell.Font.Bold = true; }}Thanks,
Shinu.
0
Nurietin
Top achievements
Rank 1
answered on 21 Mar 2012, 10:55 AM
Thanks Jayesh Goyani
now I want to check whether item has child ?
now I want to check whether item has child ?
if (item.HasChildItems)
item["Index"].ForeColor = System.drawing.Color.red
else
item["Index"].ForeColor = System.drawing.Color.red
but No working
Thanks,
Mehmedov
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Mar 2012, 11:18 AM
Hello,
Can you please tell me in which event you write this code?
Thanks,
Jayesh Goyani
Can you please tell me in which event you write this code?
Thanks,
Jayesh Goyani
0
Nurietin
Top achievements
Rank 1
answered on 21 Mar 2012, 11:23 AM
I tried these
OnItemCreated or OnItemDataBound
Thanks,
Mehmedov
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Mar 2012, 11:23 AM
Hello,
Please check this below code snippet.
if (item.HasChildItems)
{
item["ID"].Font.Bold = true;
}
Thanks.
Jayesh Goyani
Please check this below code snippet.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource" ondetailtabledatabind="RadGrid1_DetailTableDataBind" onprerender="RadGrid1_PreRender"> <MasterTableView HierarchyDefaultExpanded="true"> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID"> </telerik:GridBoundColumn> </Columns> <DetailTables> <telerik:GridTableView> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID1"> </telerik:GridBoundColumn> </Columns> </telerik:GridTableView> </DetailTables> </MasterTableView> </telerik:RadGrid>protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e) { DateTime dt = new DateTime(); dynamic data = new[] { new { ID = 1, Name ="Name1", customdate=dt}, new { ID = 2, Name = "Name2", customdate=dt}, new { ID = 3, Name = "Name3", customdate=dt}, new { ID = 4, Name = "Name4", customdate=dt.AddYears(2011)}, new { ID = 5, Name = "Name5", customdate=dt} }; e.DetailTableView.DataSource = data; } protected void RadGrid1_PreRender(object sender, EventArgs e) { foreach (GridDataItem item in RadGrid1.MasterTableView.Items) { if (item.HasChildItems) { item["ID"].ForeColor = System.Drawing.Color.Red; } else { item["ID"].ForeColor = System.Drawing.Color.Yellow; } } }protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { DateTime dt = new DateTime(); dynamic data = new[] { new { ID = 1, Name ="Name1", customdate=dt}, new { ID = 2, Name = "Name2", customdate=dt}, new { ID = 3, Name = "Name3", customdate=dt}, new { ID = 4, Name = "Name4", customdate=dt.AddYears(2011)}, new { ID = 5, Name = "Name5", customdate=dt} }; RadGrid1.DataSource = data; }if (item.HasChildItems)
{
item["ID"].Font.Bold = true;
}
Thanks.
Jayesh Goyani
0
Nurietin
Top achievements
Rank 1
answered on 03 Apr 2012, 07:50 AM
I solved the problem
foreach (GridDataItem item in RadGridDocument.MasterTableView.Items)
{
var currDocument = Session.GetDocument((int)item.GetDataKeyValue("ID"));
if (currDocument.ParentID > 0)
item["Index"].Font.Bold = true;
else
item["Index"].Font.Bold = false;
}
foreach (GridDataItem item in RadGridDocument.MasterTableView.Items)
{
var currDocument = Session.GetDocument((int)item.GetDataKeyValue("ID"));
if (currDocument.ParentID > 0)
item["Index"].Font.Bold = true;
else
item["Index"].Font.Bold = false;
}