Reputation: 31
i am trying to bring a ListView Control into my page, a basic blank plain one, without column names or other template features.
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.
I tried this simple piece of code just to see what could happen, but nothing gets printed on the aspx page. 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>
Upvotes: 1
Views: 1083
Reputation: 17370
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!
Upvotes: 0
Reputation: 2828
ListView requires you to bind some data to it for it to render something. Take a look at this article which walks you through using the ListView control.
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.
Upvotes: 1