Click here to Skip to main content
15,887,453 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
<asp:DropDownList runat="server" ID="RecordSelect" 
                            OnSelectedIndexChanged="SelectionChanged"
                            AutoPostBack="true" >


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




/edit
This is the code that populates the drop down called from Page_Load
C#
protected void Load_Entity_Items(string entity_Name, string record_Name, string recordid)
        {
            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, getCred(), null))
            {
                serviceProxy.EnableProxyTypes();
                QueryExpression qe = new QueryExpression();
                qe.EntityName = entity_Name;
                qe.ColumnSet = new ColumnSet();
                qe.ColumnSet.Columns.Add(record_Name);
                qe.ColumnSet.Columns.Add(recordid);
                OrderExpression oe = new OrderExpression();
                oe.AttributeName = record_Name;
                oe.OrderType = OrderType.Ascending;
                qe.Orders.Add(oe);
                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)
                            break;
                }
                RecordSelect.DataSource = lst;
                RecordSelect.DataTextField = "ItemLabel";
                RecordSelect.DataValueField = "ItemValue";
                RecordSelect.DataBind();
                RecordSelect.SelectedValue = _accountId.ToString();
            }
            
        }
Posted
Updated 4-Oct-11 17:30pm
v4
Comments
ARBebopKid 4-Oct-11 11:06am    
Where in your code are you setting the value of the dropdownlist after the postback?

Hi,

Make sure that your method must call like below code
C#
protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
             Load_Entity_Items(entity_Name,record_Name,recordid)

     }
 }


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