tags:

views:

27

answers:

3

Hello, I am newbie in ASP.NET. I have prepared an arraylist of Product and want to display in the page. Easiest way is binding the arraylist to GridView.

But I don't have flexibility there, since it will automatically generate a TABLE behind the scene. Is there any other way to give us flexibility to really control the HTML output, for e.g i want to display using UL tag instead of TABLE tag.

+2  A: 

You can prefer using Repeater Control instead. With Repeater's templates, you can easily inject your html output to your output.

Here there's an exapmle of using Repeater. Actually example also try to add a table but, the topic is to show you how to use templates.

Canavar
hello thanks for your answer. it seems the right answer the only thing from what I saw the repeater needs DataSourceID -- meanwhile I have an ArrayList. Any clue?
iwan
No you can set your ArrayList to Repeater's DataSource property and call DataBind Method.
Canavar
+1  A: 

Use

Response.Write("<ul><li>item1</li><li>item1</li><li>item1</li><li>item1</li></ul>")

You get all the control u need with that

Pierreten
Hello, thanks for your answer. But could you explain me more what shall I do in aspx and aspx.cs files? Your comment make sense for me only at ASP (not ASP.NET??)
iwan
Oh ok.. now i understand that we could write Response.Write inside aspx.cs -- but then it kinds of breaking master page. So i add label and populate the label with the right UL/LI tags. Thanks!!!!
iwan
+1  A: 
var products = new ArrayList();
products.Add("product1");
products.Add("product2");
products.Add("product3");

var builder = new StringBuilder();

foreach (var product in products)
{
    builder.Append("<li>" + product + "</li>");
}

Response.Write("<ul>" + builder.ToString() + "</ul>");
Ray Vega
Hello, thanks for your answer. But could you explain me more what shall I do in aspx and aspx.cs files? Your comment make sense for me only at ASP (not ASP.NET??)
iwan
@iwan- the code above can be added in the `Page_Load` method or some event handler like for a button in the code behind `*.aspx.cs` file of the `*.aspx` page file. The `Response.Write` will return the raw HTML `<ul><li>product1</li><li>product2</li><li>product3</li></ul>` created by the stringbuilder to the clientside browser.
Ray Vega