Vijaianand
Top achievements
Rank 1
Vijaianand
asked on 23 Dec 2011, 03:24 PM
I am trying to change the color of the header row when its in expanded mode. I tried the below code but didn't work.
Any other way?
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
If TypeOf e.Item Is GridGroupHeaderItem Then
Dim gpheader As GridGroupHeaderItem = CType(e.Item, GridGroupHeaderItem)
If item.Selected Then
gpheader.BackColor = Drawing.Color.DarkSeaGreen
End If
End Sub
Any other way?
5 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Dec 2011, 06:50 PM
Hello VIJAIANAND,
Thanks,
Jayesh Goyani
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
style
type
=
"text/css"
>
.MyClass
{
background-color:Red !important;
}
</
style
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowSorting
=
"true"
ShowGroupPanel
=
"true"
GroupingEnabled
=
"true"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
DataKeyNames
=
"ID,SrNo"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
UniqueName
=
"ID"
HeaderText
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
UniqueName
=
"Name"
HeaderText
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name1"
UniqueName
=
"Name"
HeaderText
=
"Name1"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowDragToGroup
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"ID"
,
typeof
(System.Int32));
dt.Columns.Add(
"Name"
,
typeof
(System.String));
dt.Columns.Add(
"SrNo"
,
typeof
(System.Int32));
dt.Rows.Add(
"1"
,
"Name1"
,
"1"
);
dt.Rows.Add(
"2"
,
"Name2"
,
"2"
);
dt.Rows.Add(
"3"
,
"Name3"
,
"3"
);
dt.Rows.Add(
"4"
,
"Name4"
,
"4"
);
RadGrid1.DataSource = dt;
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridGroupHeaderItem)
{
e.Item.CssClass =
"MyClass"
;
}
}
Thanks,
Jayesh Goyani
0
Vijaianand
Top achievements
Rank 1
answered on 27 Dec 2011, 03:12 PM
This is not right code or solution. There is no checking on whether group is expanded or not. You are only checking its a group row. Please don't put solutions without reading the questions.
0
Richard
Top achievements
Rank 1
answered on 27 Dec 2011, 03:39 PM
Hello VIJAIANAND,
Have you looked at this code library thread? It points to a code library sample that should help you determine if the GroupRow Header is in an expanded state.
ExpandCollapseGroupedGridOnDoubleClickingTheGroupHeader
Hope this helps a bit.
Cheers!
Have you looked at this code library thread? It points to a code library sample that should help you determine if the GroupRow Header is in an expanded state.
ExpandCollapseGroupedGridOnDoubleClickingTheGroupHeader
Hope this helps a bit.
Cheers!
0
Vijaianand
Top achievements
Rank 1
answered on 27 Dec 2011, 07:56 PM
That example gives an idea how I can do it but that incorporating "Dblclick" to invoke the expansion and identify its expanded or not. But a click event on the groupheader/groupsplitter column is already existing functionality. I thought it would be standalone property for the groupitem header to see whether expanded or not?
0
Vijaianand
Top achievements
Rank 1
answered on 27 Dec 2011, 08:14 PM
I was able to extract what I wanted it from the code snippet you provided and it works. Here you go,
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
For Each grphdr As GridGroupHeaderItem In RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)
If grphdr.Expanded Then
grphdr.BackColor = Drawing.Color.DarkSeaGreen
End If
Next
End Sub