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

Different Group Header based upon GridBoundColumn

4 Answers 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 23 Jul 2015, 07:07 PM

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

Sort by
0
Angel Petrov
Telerik team
answered on 28 Jul 2015, 11:51 AM
Hi Kurt,

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>
The above code access the DataItem's Section value which should be available since you are grouping by that field.

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kurt Kluth
Top achievements
Rank 1
answered on 28 Jul 2015, 08:35 PM

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>
 

 

 

0
Accepted
Angel Petrov
Telerik team
answered on 31 Jul 2015, 08:24 AM
Hi,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kurt Kluth
Top achievements
Rank 1
answered on 31 Jul 2015, 02:19 PM

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.

Tags
Grid
Asked by
Kurt Kluth
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Kurt Kluth
Top achievements
Rank 1
Share this question
or