如何在运行时为C#中的网站创建listview? [英] How create listview for website in C# at runtime ?

查看:90
本文介绍了如何在运行时为C#中的网站创建listview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时使用代码在c#中为网站创建Listview?



如何在listview中添加标签,按钮以及事件。



主要问题是无法在列表视图中添加ItemTemplate。



要求:需要使用后端代码在面板中添加多个listview。



所以我创建了一个Panel并使用for循环。我可以添加标签,下拉列表(带有selectedindexchange事件),带有Panel的按钮。



但坚持将listview添加到Panel。



Windows应用程序中有选项。但坚持使用web应用程序,无法找到任何解决方案。



请提供有用的链接或任何建议我该如何处理。





编辑:您可以将其评分为1.但请注释,所以我可以改进我的问题或提供更多细节。



我尝试过:



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.


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:

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.
}

推荐答案

我还没有使用过asp.net一段时间但是你看过这篇MS帖子 [ ^ ]?



那里有一些很好的例子。
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.


这篇关于如何在运行时为C#中的网站创建listview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆