views:

31

answers:

1

Hi there,

What I want to do is to create something like that hotmail/facebook-style list of selected contacts.. with 1 little block and a "X" for removing each item.

How could I achieve that in .NET?

I thought of creating new labels "on the fly" and use .NET's Ajax UpdatePanel..

But, can I do it? if yes, how can i create a label on the fly, and put it just where I want?

I want the items to be created in a list. (<ul>)

A: 

Assuming you have a Panel somewhere on your site:

Label myLabel = new Label();
myLabel.Text = "My Name";
myLabel.CssClass = "labelClass";
pnlItems.Controls.Add(myLabel);


To have ul / li items (or something completely customisable):

HtmlGenericControl ulControl = new HtmlGenericControl("ul");
pnlItems.Controls.Add(ulControl);
foreach (object myThing in myItems)
{
    HtmlGenericControl itemControl = new HtmlGenericControl("li");
    itemControl.InnerHtml = myThing.GetMarkup();
    ulControl.Controls.Add(itemControl);
}

Note this is untested - I'm fairly sure you can add controls to an Html Generic Control.

ck
Nice :) What if i need to markup and organize it better, and want to set it right into a <ul> inside that Panel?
Vitor Reis
Then you should probably use a BulletedList control.
recursive
Thanks so much ck! your solution worked really really well for me :)
Vitor Reis