Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How create Listview for website in c# at runtime using code ?

Stuck how to add label,button in listview with event.
OR
the main issue is unable to add "ItemTemplate" in listview.

Requirment : "Need to add multiple listview in a panel using backend code."

So I create a Panel and use for loop for this. I am able to add label, dropdownlist(with selectedindexchange event), button with Panel.

But stuck in adding listview to Panel.

There is option in windows application. But stuck for webapplication, unable to found any solution.

please provide a usefull link or any suggestion how can I proceed.


Edit: You can Rate it to 1. But please comment also, So I can improve my question or provide more detail's.

What I have tried:

C#
DataTable dt_att= getdatafromFunction();
for (int i = 0; i < dt_att.Rows.Count; i++)
{

DataTable dt_at_value = getdatafromFunction2(dt_att.Rows[i]["id"].ToString());
ListView listView1 = new ListView();
listView1.LayoutTemplate = new LayoutTemplate();
listView1.ItemTemplate = new ItemTemplate();

listView1.DataSource = dt_at_value; 
listView1.DataBind();

 listView1.ItemDataBound += new EventHandler<ListViewItemEventArgs>(lst_attribute_ItemDataBound);
listView1.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lst_attribute_ItemCommand);

pnl_attributelist.Controls.Add(listView1); //pnl_attributelist is a Panel.
}
Posted
Updated 29-Aug-18 21:51pm
v2

1 solution

I havent used asp.net for a while but have you taken a look at this MS Post[^] ?

There are some good examples in there.
 
Share this answer
 
Comments
Hemant Singh Rautela 30-Aug-18 3:54am    
I saw it already, But it is not for runtime listview control addition.

It's all about create listview on design page and bind data from code behind.

But I am working about addition of control at runtime. without writing listview conrol on design page. All code in code behind.
Richard Maly 30-Aug-18 4:04am    
again, not sure but once you instantiate your ItemTemplate can you do listView1.ItemTemplate = "some html"?

otherwise a little reading around suggests you might have to create a class inherited from iItemTemplate which has the html in it, which sounds a pig.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900