Dynamic ListViewDataGroup

1 Answer 17 Views
ListView
SOPHIE
Top achievements
Rank 1
SOPHIE asked on 04 Jun 2021, 07:20 AM

Hi, 

I'm trying to create a dynamic ListViewDataGroup with code-behind value for 'groupField', is that possible ?


<telerik:RadListView ID="lv_xxx"
                EnableViewState="false"
                ItemPlaceholderID="itemPlaceHolder"
                OnItemDataBound="lv_xxx_ItemDataBound"
                runat="server"  >

                <LayoutTemplate>
				.....
				</LayoutTemplate>

                <DataGroups > 
                <telerik:ListViewDataGroup GroupField='<%= this.XXX >' DataGroupPlaceholderID="groupPlaceHolder" SortOrder="Ascending"  > 
                        <DataGroupTemplate>
                            <tr>
                                <td>
                                    <%# (Container as RadListViewDataGroupItem).DataGroupKey %>
                                </td>
                            </tr>
                            <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
                        </DataGroupTemplate>
                    </telerik:ListViewDataGroup>
                </DataGroups>

                <EmptyDataTemplate> 
                </EmptyDataTemplate>

                <ItemTemplate>
				......
				/ItemTemplate> 
           </telerik:RadListView> 

 

 

thanks

 

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 08 Jun 2021, 12:49 PM

Hi Sophie,

Unfortunately, you can not use a server binding expression ('<%# %>') directly in the ListViewDataGroup declaration as it does not have a DataBinding event.

Instead, you can use the OnDataBinding event of the RadListView and set programmatically the desired field to the DataGroup:

protected void RadListView1_DataBinding(object sender, EventArgs e)
{
    (sender as RadListView).DataGroups[0].GroupField = "BrandName";
}

I hope this will help you achieve the desired. 

Please let me know if any further questions come up.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ListView
Asked by
SOPHIE
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or