What I need to do is set a ​GroupHeaderTemplate link to 1 of 2 URL's based upon the value of a ​GridBoundColumn.
If Section="Marketing" then display 1st URL
else
display 2nd URL
How would I go about doing this?
<
GroupHeaderTemplate
>
<
a
href='/CUTracking/Notes/Default.aspx?
Section
=
FMS
&SearchCharterNum=<%# Eval("Charter_Num") %>' title="View <%# Eval("CUName")%> notes section"><%# Eval("CUName")%></
a
>
</
GroupHeaderTemplate
>
<
telerik:GridBoundColumn
HeaderText
=
"SECTION"
UniqueName
=
"Section"
FilterControlAltText
=
"Filter column column"
DataField
=
"Section"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ItemStyle
HorizontalAlign
=
"Center"
/>
<
HeaderStyle
HorizontalAlign
=
"Center"
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
I attempted doing it on RadGrid.ItemDataBound but received an error because it didn't have a dataitem called "Section".
If DataBinder.Eval(e.Item.DataItem, "Section") = "Marketing" Then
4 Answers, 1 is accepted
I am not sure what value should be appended to the URL but you can use a conditional statement inside the GroupHeaderTemplate for achieving this. A possible realization of such an approach is available in the following code snippet:
ASPX:
<
GroupHeaderTemplate
>
<
a
href='/CUTracking/Notes/Default.aspx?
Section
=
FMS
&SearchCharterNum=<%#DataBinder.Eval(Container.DataItem,"Section").ToString()=="Marketing"?"some url":"anotherURL"%>'>Text</
a
>
</
GroupHeaderTemplate
>
If the suggested approach does not prove helpful please share with us the entire page contents(markup and code-behind) so we could examine the implementation.
Regards,
Angel Petrov
Telerik
That did help which I believe put me a bit closer to a solution. However I receive an error when attempting to run this code.
Additional information: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Section'.
The two URLS are:
/CUTracking/Notes/default.aspx?Section=Marketing&SearchCharterNum=<%# Eval("Charter_Num")%>
&
/CUTracking/Notes/Default.aspx?Section=FMS&SearchCharterNum=<%# Eval("Charter_Num") %>"
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SrcNotes"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
DataSourceID
=
"SrcNotes"
>
<
GroupHeaderTemplate
>
<
a
href='<%#DataBinder.Eval(Container.DataItem, "Section").ToString()%> == "Marketing"?"/CUTracking/Notes/default.aspx?Section=Marketing&SearchCharterNum=<%# Eval("Charter_Num")%> ":"/CUTracking/Notes/Default.aspx?Section=FMS&SearchCharterNum=<%# Eval("Charter_Num") %>"' title="View <%# Eval("CUName")%> notes section"><%# Eval("CUName")%></
a
>
</
GroupHeaderTemplate
>
<
GroupByExpressions
>
<
telerik:GridGroupByExpression
>
<
SelectFields
>
<
telerik:GridGroupByField
FieldAlias
=
"CUName"
FieldName
=
"CUName"
HeaderValueSeparator
=
" : "
></
telerik:GridGroupByField
>
<
telerik:GridGroupByField
FieldAlias
=
"Charter_Num"
FieldName
=
"Charter_Num"
/>
</
SelectFields
>
<
GroupByFields
>
<
telerik:GridGroupByField
FieldName
=
"CUName"
SortOrder
=
"Descending"
></
telerik:GridGroupByField
>
</
GroupByFields
>
</
telerik:GridGroupByExpression
>
</
GroupByExpressions
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Comments"
HeaderText
=
"Note"
UniqueName
=
"Comments"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Font-Bold
=
"True"
Width
=
"425"
/>
<
ItemStyle
Wrap
=
"true"
Width
=
"425"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridDateTimeColumn
DataField
=
"FollowupDate"
DataFormatString
=
"{0:MM/dd/yyyy}"
HeaderText
=
"Follow-up Date"
UniqueName
=
"FollowupDate"
DataType
=
"System.DateTime"
>
<
HeaderStyle
HorizontalAlign
=
"right"
Font-Bold
=
"true"
/>
<
ItemStyle
HorizontalAlign
=
"Right"
Wrap
=
"false"
/>
</
telerik:GridDateTimeColumn
>
<
telerik:GridBoundColumn
DataField
=
"UserName"
HeaderText
=
"Creator"
UniqueName
=
"UserName"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Font-Bold
=
"True"
/>
<
ItemStyle
Wrap
=
"False"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Priority"
HeaderText
=
"Status"
UniqueName
=
"Status"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Font-Bold
=
"True"
/>
<
ItemStyle
Wrap
=
"False"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"File"
HeaderText
=
"File"
>
<
ItemTemplate
>
<
a
href
=
"/NoteFiles/<%# DataBinder.Eval(Container.DataItem, "
FileLoc")%>" target="_blank" title="Open file"><%# DataBinder.Eval(Container.DataItem, "FileDesc")%></
a
>
</
ItemTemplate
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Font-Bold
=
"True"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"SECTION"
UniqueName
=
"Section"
FilterControlAltText
=
"Filter column column"
DataField
=
"Section"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ItemStyle
HorizontalAlign
=
"Center"
/>
<
HeaderStyle
HorizontalAlign
=
"Center"
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
The described behavior is expected as the data is not grouped by the Section field. Moreover inside the group the rows may contain different values for the Section column. From that point of view the targeted scenario does not seem correct. Can you please elaborate in detail on the functionality you want to implement?
Regards,
Angel Petrov
Telerik
Angel,
Thank you as you helped me figure things out. I had to add section to my grouping and things began to fall into place.