Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate link buttons dynamically

Status
Not open for further replies.

kalkumar

Programmer
Jul 7, 2006
40
US
Hi,

In my application I have one file upload control. When the user selectes a file to upload and when he clicks on Attach button I need to show him the file name of the file he selected to upload and also show the Remove link button after the file name. In this case I need to generate link button dynamically.

I wrote a code like the following:

protected void btnAttach_ServerClick(object sender, EventArgs e)
{

string strFileName = MyFile.PostedFile.FileName;string c = System.IO.Path.GetFileName(strFileName);
listBoxAttachedFiles.Items.Add(c);

LinkButton b = new LinkButton();

b.Text = "Remove";
b.ID = "LB_" + b.Text;

b.Style.Add("display", "block");
listBoxLinks.Controls.Add(b);

//Panel1.Controls.Add(b);

}

With the above code it is showing only th file name in the listbox it is not showing the Remove button in the listboxlinks list box.

How to generate the link button and and write event when the remove is clicked i have to remove the corresponding file name from the other listbox.

Thanks in advance.
 
You can't add controls to the listbox, you can add listitems to the items collection. You will have to let the user select the item(s) they want to remove and click a linkbutton or button outside the listbox. Then loop through the items in the listbox and remove the ones that are selected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top