I have a dropdown that is bound to a database. Depending on the value that is selected information shows in a gridview below. Also depending on the selected value if a user clicks on a link they get redirected to another page. That is all working except when the page loads it defaults to the first value depending on the query string. If the link is clicked on before the drop down value is changed it does not do what I want it to do because it does not recognize the selected value in the drop down for some reason. So I need to find the value of of that first item so that it redirects the user to the right place. I need to use an if statement probably, but that is all I know. Can someone please help me?

Thank you,
Jesi

Recommended Answers

All 5 Replies

You could set a default URL string value on the page generated as the first value obtained at the time of the dropdown's population. Then set the dropdown selected item changed event handler to change that string value and use the string as your URL to load instead of using the selected item property as the URL.

Basically...

string linkURL = dropDownDataPopulationFirstValue
dropDownName_SelectedIndexChanged Event
linkURL = dropDownName.SelectedIndex.Value.ToString()
ClickableLink = linkURL

No, that's not actual code, just the outline of how to do it.

Hope that helps :) Please remember to mark solved once the issue is resolved.

I'm not sure that will work, here's what I have:

overLoadEventHyper.NavigateUrl = "~/SignupForAnEventOccurrence.aspx?eventAuid=" + Request.QueryString["eventAuid"] + "&eventOccurrencesAuid=" + eventOccurrenceDrp.SelectedValue;

but it does not work for the first value if it has not been changed.


thanks

string eventOccurrenceUrl = --determined at time of eventOccurrenceDrp population as first value in the dropdown--;

protected void eventOccurrenceDrp_SelectedIndexChanged(object sender, EventArgs e)
{
    eventOccurrenceUrl = eventOccurrenceDrp.SelectedValue;
}

overLoadEventHyper.NavigateUrl = "~/SignupForAnEventOccurrence.aspx?eventAuid=" + Request.QueryString["eventAuid"] + "&eventOccurrencesAuid=" + eventOccurrenceURL;

I would leave it up to you to figure out where in your code each part of that needs to go but the concept is simple enough... at the time that eventOccurrenceDrp is populated the initial value of eventOccurrenceUrl is populated as well. Any time the drop down selection is changed it changes the string value to correspond.

Hope this helps :)

Thanks Lusiphur, I guess all I had to do was:

if (!IsPostBack)
            {
                eventOccurrenceDrp.DataBind();
            }
                overLoadEventHyper.NavigateUrl = "~/SignupForAnEventOccurrence.aspx?eventAuid=" + Request.QueryString["eventAuid"] + "&eventOccurrencesAuid=" + eventOccurrenceDrp.SelectedValue;
        }

so databinding it fixed my issue, thanks for the help again.

so databinding it fixed my issue, thanks for the help again.

I got diverted by other threads but I was also going to say that the issue may have simply been a matter of setting a 'default' selected item in the drop-down at time of binding as the issue you mentioned before seemed as though it was trying to use a selected item when none were "selected".

But I'm glad you got it sorted :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.