tags:

views:

695

answers:

2

Hi folks,

This is a puzzle for me, I am able to get three DropDownLists to behave like a cascade (it fetches the correct data) but where I run into problem is where I try to set the value for the dropdownlist based on the value of the querystring.

Only the first dropdownlist seems to take it's value from the querystring. The other two does not. In fact the 3rd DropDownlist will also exhibit the error below (it almost looks like the control isn't bound yet:

'ddlStation' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

FYI, here is the portion that sets the DropDownList in the Page_Load event:

// see if there is any querystring and set dropdownlist accordingly
                if (Request.QueryString["cell"] != null)
                {
                    ddlCell.SelectedValue = Request.QueryString["cell"].ToString();
                    if (Request.QueryString["subcell"] != null)
                    {
                        ddlSubCell.SelectedValue = Request.QueryString["subcell"].ToString();
                        if (Request.QueryString["station"] != null)
                        {
                            ddlStation.SelectedValue = Request.QueryString["station"].ToString();
                        }
                    }
                }

Any help is appreciated!

+2  A: 

You can only set the SelectItem/Value/Text after databinding has happened.

leppie
+1  A: 

Hi Leppie,

You're right that the databind must happen first..

What I kind of figured out is that the setting of the dropdownlist should be in the Databound event of each dropdownlist (rather than in the Page_Load event in the original).

It works now :)

mrsaiful
should move this to a comment on leppie's answer
sixlettervariables