Click here to Skip to main content
15,789,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drop down list that I'm trying to fire a redirect when the index changes. Technically all I want to do is refresh the page with the new selected value passed to the url. My drop down list is data bound with Account Names for Label and GUID's for Values from CRM 2011. My code behind pulls in form values based on the GUID passed through the url.
<asp:DropDownList runat="server" ID="RecordSelect" 
                            AutoPostBack="true" >

When debugging this function doesn't fire. The page refreshes, but the DDL goes back to the original index.
protected void SelectionChanged(object sender, EventArgs e)
            Response.Redirect("http://url/account.aspx?field1=" + ((DropDownList)sender).SelectedValue);

This is the code that populates the drop down called from Page_Load
protected void Load_Entity_Items(string entity_Name, string record_Name, string recordid)
            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, getCred(), null))
                QueryExpression qe = new QueryExpression();
                qe.EntityName = entity_Name;
                qe.ColumnSet = new ColumnSet();
                OrderExpression oe = new OrderExpression();
                oe.AttributeName = record_Name;
                oe.OrderType = OrderType.Ascending;
                EntityCollection ec = serviceProxy.RetrieveMultiple(qe);

                List<picklistoptions> lst = new List<picklistoptions>();
                foreach (Entity act in ec.Entities)
                    lst.Add(new PickListOptions() { 
                        ItemLabel = act[record_Name].ToString(), 
                        ItemValue = act[recordid].ToString() 
                    if (ec.Entities.IndexOf(act) == 24)
                RecordSelect.DataSource = lst;
                RecordSelect.DataTextField = "ItemLabel";
                RecordSelect.DataValueField = "ItemValue";
                RecordSelect.SelectedValue = _accountId.ToString();
Updated 4-Oct-11 18:30pm
ARBebopKid 4-Oct-11 11:06am    
Where in your code are you setting the value of the dropdownlist after the postback?


Make sure that your method must call like below code
protected void Page_Load(object sender, EventArgs e)
     if (!IsPostBack)


All the Best
Share this answer
Hi There,

I think you got to persist your selection during Postback, as you are rebinding your Dropdown in PageLoad event, this will loose your selected index value from ViewState. Try to store it in some HiddenField/Viewstate so that you can read it back and set the selected index after binding your Dropdown.

Please let me know if any further clarification is required.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900