.net下拉列表OnSelectedIndexChange事件 [英] .net Drop Down List OnSelectedIndexChange Event

查看:146
本文介绍了.net下拉列表OnSelectedIndexChange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,当索引更改时,我试图触发重定向.从技术上讲,我要做的就是使用传递给url的新选定值刷新页面.我的下拉列表是与CRM 2011中的标签的帐户名"和值的GUID"绑定的数据.我背后的代码基于通过URL传递的GUID提取表单值.

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" 

                            OnSelectedIndexChanged="SelectionChanged"

                            AutoPostBack="true" >



调试时,此功能不会触发.页面刷新,但是DDL返回到原始索引.



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);
        }





/edit
这是填充从Page_Load
调用的下拉菜单中的代码





/edit
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))
            {
                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();
            }
            
        }

推荐答案



确保您的方法必须像下面的代码那样调用
Hi,

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

     }
 }



最好的



All the Best




我认为您必须在回发期间保持选择,因为您要重新绑定PageLoad事件中的Dropdown,这将从ViewState中释放所选的索引值.尝试将其存储在某些HiddenField/Viewstate中,以便在绑定Dropdown后可以将其读回并设置选定的索引.

请让我知道是否需要进一步澄清.
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.


这篇关于.net下拉列表OnSelectedIndexChange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆