Question

I am trying to add a new item in a ListView on itemdatabound. What is the best way to do it?

Data comes from a dataset with

        TopicReplyListView.DataSource = TopicReplyDataTable;
        TopicReplyListView.DataBind();

on

         TopicReply_ItemDataBoundEvent

I want to add text such as "TEST ITEM" and continue to bind

my TopicReply_ItemDataBoundEvent is

    protected void TopicReply_ItemDataBoundEvent(object sender, ListViewItemEventArgs e)
    {
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        ListViewDataItem dataItem = (ListViewDataItem)e.Item;
    }
    }
Was it helpful?

Solution

Where are you actually trying to add the "Test Item" text?

If you need to add an item to the data source then just do that in the data table before assigning it to the datasource.

If you need to change something in the ItemTemplate then maybe use the ItemCreated event on the list view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top