multiple dropdownlist controls for order items

On the order confirmation page for an ecommerce site, I am putting together a file upload control for customer to upload graphic files for the order. I've got a dropdownlist that pulls a print location from each order item  and adds that location to the file name as it is uploaded. One of the things I'm having trouble with is getting the dropdown list to repeat for each order item. It will do it for only the first item. How can I get it to repeat?
Here is the current code:
foreach (OrderItem item in _Order.Items)

            if (item.Inputs.Count > 0)
               DropDownListTemplateFields.DataSource = item.Inputs;
               DropDownListTemplateFields.Items.Insert(0, " - Select Print Location From List - ");
               DropDownListTemplateFields.Items.Add("One File for all Print locations");
               DropDownListTemplateFields.Items.Add("Sound File(s)");

Who is Participating?
jmestepConnect With a Mentor Author Commented:
I think I'm making progress.
Later on in the class, I use the value selected in the dropdown list and I've got an error there

 protected void UploadButton_Click(object sender, EventArgs e)
        bool success = true;
        if (UploadedFile.HasFile)
            if (UploadedFile.PostedFile.ContentLength < 204800000)//195MB
                string selectedItem = DropDownListTemplateFields.SelectedItem.Text;
How can I pick up the value now? I've tried _value and d.SelectedItem.Text

tiagosalgadoConnect With a Mentor Commented:
You can use ASP.NET Repeate Control for that.
jmestepAuthor Commented:
Duh, I should have thought of that. I am also trying to show the product name, then the ddl, then next product name, then ddl. That might be a way to do both- use the header. I'll try tomorrow and post back.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Yes, in Repeater control, you can include all information that you want to repeat.
jmestepAuthor Commented:
Now the page can't find the dropdown list:
<asp:Repeater ID="OrderItemRepeater" runat="server" EnableViewState="true">
            <asp:DropDownList ID="DropDownListTemplateFields" Visible="true" runat="server"  DataTextField="Name" DataValueField="OrderItemInputId"  EnableViewState="true">
            <asp:ListItem Value="" Text=""></asp:ListItem>

To get all dropdownlists in your reapeter you need to do this

string _value = "";
        foreach (RepeaterItem item in OrderItemRepeater.Items)
            DropDownList d = item.FindControl("DropDownListTemplateFields") as DropDownList;
            if (d != null)
                _value = d.SelectedValue;

Open in new window

jmestepAuthor Commented:
I think what I need to do is move the code that validates the upload out of the button click and then put code on each button click that is generated within the repeater to call it?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.