In news:5C15A6E2-7EAF-4F0D-9C22-(E-Mail Removed),
talvaro <(E-Mail Removed)> wrote:
> HELP!!!!
>
> I have a ListBox control, when one of the item is clicked I am using a
> series of porperties and methos for Reponse class in order to allow
> download diff files. The problem is that it doesn't matter what is
> clicked after a item within the listBox is cliecked always the
> SelectedIndexChanged method for the listBox is executed. Here is the
> code:
>
> private void pdfListBox_SelectedIndexChanged(object sender, EventArgs
> e) {
> try
> {
> pdfListBox.Enabled = false;
> Response.ClearHeaders();
> Response.ContentType = "application/pdf";
> Response.Clear();
> Response.AppendHeader("Content-Disposition",
> "attachment;Filename=Report.pdf");
> Response.TransmitFile(pdfListBox.SelectedValue);
> HttpContext.Current.ApplicationInstance.CompleteRequest();
> }
>
> Any help wil lbe greatlly appreciated.
I am not sure what your question is. The SelectedIndexChanged method will
always be executed.
If you are not getting proper file names out, it might be because each
ListItem contains both value and text. Depending on how you are loading the
listbox, value may be the 'index' not the displayed file name.Try this:
string filename = pdfListBox.SelectedItem.Text;
Response.TransmitFile(filename);
BTW the reason I broke it into two statements is that way you can use the
debugger to watch the string filename.
--
Jim
"Remember, an amateur built the Ark; professionals built the Titanic."
|