开发者

dynamically add <asp:linkbutton>

i have a question about asp : i have a list of ids that are returned from the server to my webpage . Can i return it in a div under a asp.net control ? :

div_containing_link += " < asp:linkbutton id="bleah" runat='server' onclientclick='java_function()' onclick='dosomething' />"

if not , how can i do so ? the particular example is that i want to return a list of people ( friends of my friends -- i'm developing as a project a facebook-like app ) and when 开发者_JAVA技巧i click on them i want to send to the server that we should become friends and make the changes needed in the database .


Set your div to runat='server' then add each LinkButton control using

MyDiv.Controls.Add(new LinkButton());

As long as your div is called MyDiv you can then dynamically assign controls such as in your case hyperlinks to the actual div. You could also set some properties before you add them like so:

for( int i =0; i<20; i++)
 {
  LinkButton l = new LinkButton();
  l.ID = i;
  l.Text = "Hello " + i.ToString();
  MyDiv.Controls.Add(l);
  l=null;
 }


It is unclear how you want to create the links. If you have a list of IDs and want to use a DataBound server controls that handel IEnumerable as Datasource, you can use a ListView and assign the specific values of your business object to a LinkButton in the ItemDataTemplate

Otherwise, if you really want to use string concatenation, you might have a look at this article http://www.tomot.de/en-us/article/3/asp.net/create-a-control-in-the-codebehind-and-retrieve-its-rendered-output, that should explain, how you render a serverside control to a string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜