How to create LinkButton in Repeater control from DataSet?

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

I want to read information out of a database at runtime (names of files available to download) and create a list of linkbuttons that the user can click on to download the file(s).

How can I accomplish this.

I've got this far:

In the html:

....
table>
<asp:Repeater ID="softwareList" Runat="server">
<ItemTemplate>
<tr>
<td>
<asp:LinkButton Runat="server">
<%# DataBinder.Eval(Container.DataItem,"SoftwarePath") %>
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

In the codebehind page:

private void Page_Load(object sender, System.EventArgs e)
{
if ( !Page.IsPostBack )
{
sqlDataAdapter1.Fill(dataSet11);
softwareList.DataSource = dataSet11;
softwareList.DataBind();
}
}

This reads the information out of the database and displays the items as links, but how do I "bind" the links to be able to download the file.
For example,

say my list looks like:

your_software_one.exe
more_software.exe

what more do I need to do to create the "click" event for each of these links to pass the filepath information to the download routine?
 
You should add an OnCommand event handler tot he LinkButtons. In that event
handler you'll need to know which thing to download, so I'd suggest also
supplying a CommandName='<%# 'DataBinder.Eval(COntainer.DataItem, "SomeIDForYourDownload")%>'
then in your event handler simply check the COmmandName to know what to send
back via Response.BinaryWrite().

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Brock,
Thaks for the reply - where/how do I add the OnCommand event handler - on
the codebehind page?
A quick snippet would be helpful - thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top