Listview with different Item Templates

1 Answer 44 Views
ListView
Hendrik
Top achievements
Rank 2
Bronze
Iron
Iron
Hendrik asked on 09 Jul 2024, 01:55 PM

I tried to figure out how to use different Item Templates within a Listview but I failed.

is it not possible ?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 11 Jul 2024, 11:05 AM

Hi Hendrik,

The ListView component has one item <Template> for all its items. If you wish to render different content for different items, then use conditional statements inside the template. See a similar example in the Grid inline editing example.

<GridCommandColumn>
            <GridCommandButton Command="Edit">Edit</GridCommandButton>

            @if ((context as ProductDto).ProductId % 2 == 0)
            {
                <GridCommandButton Command="Delete" Icon="@SvgIcon.Trash">Delete</GridCommandButton>
            }

            <GridCommandButton Command="Save">Update</GridCommandButton>
            <GridCommandButton Command="Cancel">Cancel</GridCommandButton>
        </GridCommandColumn>

 

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Tags
ListView
Asked by
Hendrik
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Dimo
Telerik team
Share this question
or