[英]Asp.Net: ListView control doesn't show
i am trying to bring a ListView Control into my page, a basic blank plain one, without column names or other template features. 我试图将ListView控件带入我的页面,这是一个基本的空白纯文本,而没有列名或其他模板功能。
What i need is a blank list view where i could load rows with text from a textbox, extracted and loaded via server side. 我需要的是一个空白列表视图,在这里我可以从文本框中加载带有文本的行,并通过服务器端提取并加载。
In Asp.Net 3.5 requirements it seems i have to set up the <LayoutTemplate>
and <ItemTemplate>
, even though i don't need them for my specific task. 在Asp.Net 3.5要求中,似乎我必须设置
<LayoutTemplate>
和<ItemTemplate>
,即使我不需要为特定任务使用它们。
I tried this simple piece of code just to see what could happen, but nothing gets printed on the aspx page. 我尝试了这段简单的代码,只是想看看会发生什么,但是没有任何内容打印在aspx页面上。 If i get rid of the two template properties still nothing gets printed on screen.
如果我摆脱了这两个模板属性,屏幕上仍然不会打印任何内容。
I may have missed some basic configuration property, could someone give me some advices? 我可能错过了一些基本配置属性,有人可以给我一些建议吗?
thanxalot 非常感谢
<asp:ListView ID="LView" runat="server">
<LayoutTemplate>
<table>
<th>
string
</th>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
string
</td>
</tr>
</ItemTemplate>
</asp:ListView>
ListView requires you to bind some data to it for it to render something. ListView要求您绑定一些数据以使其呈现某些内容。 Take a look at this article which walks you through using the ListView control.
看一下这篇文章,它引导您使用ListView控件。
http://www.codeproject.com/Articles/24570/Complete-ListView-in-ASP-NET-3-5 http://www.codeproject.com/Articles/24570/Complete-ListView-in-ASP-NET-3-5
Note that I found this with a quick Google search, I'm sure there are better tutorials. 请注意,我是通过Google的快速搜索找到它的,我相信这里有更好的教程。
Little sample: 小样:
using System;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileStream f = new FileStream(ResolveUrl("~/HelloWorld.txt"), FileMode.Open);
StreamReader sr = new StreamReader(f);
string content = sr.ReadToEnd();
ListView lv = new ListView();
Table t = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Text = content;
tr.Cells.Add(tc);
t.Rows.Add(tr);
lv.Controls.Add(t);
this.form1.Controls.Add(lv);
}
}
Updated: added actual control to the page, sorry. 更新:对页面添加了实际控制,对不起。 Good luck!
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.