开发者

How to create components (labels) on the fly? (or how to create facebook/hotmail-style to add contacts to message)

W开发者_Python百科hat 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>)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜