1

i need to fill dropdownlist and use its selected value in inline code to fill href of menu items .

example : i have DropCountry and fill it from DB then i get the location of client and set the selectedindex with this value , so i want to set href of menuitem with Query string of CountryID taken from dropCountry.selectedValue.

but he compile the inline Code before Codebehind :S

"Details.aspx?AdID=<%# DataBinder.Eval(Container.DataItem, "AdID")%>&CatID=<% Response.Write(GetIDCatFromQueryString()); %>&Country=<% i need to get value here %>"

1 Answer 1

1

Here is my solution for you:

I suspect that you are binding the menu item with datasource so the databinding of the menuitme happens before the page load where you have set the drop down list items and selected one of them so i suggest that in your page load, make the steps as following:

  1. Fill the drop down list with data
  2. Select the item from the drop down list
  3. Make the menu item binding

OR

You can fill the drop down list and select an item in the Page_OnInt event.

In Both cases you have to update you code by adding <%# YourDropDownList.SelectedValue %>

Sign up to request clarification or add additional context in comments.

4 Comments

thanks alot, the second one works fine in my case, but there are another problem : when i change the selected index manual from page, i think the event fires after page load and dropcountry.selectedvalue for inline code will get the old value
I suggest that OnInit after you have filled the drop dwon list with data and changed it's selctedvalue, make a call to the selectedIndexChanged event handler function.
yes i know but i men when user select after rendering the page .
have you tried calling the databind of the control at the end of the selected index changed event

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.