本文介绍了下拉列表的Onselectedindexchange事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个由jquery填充的下拉列表,dropdownlist有一个autopostback事件。 我想通过jquery调用dropdownlist选择的索引更改事件,将其值添加到会话中进行更改在同一页上 我尝试过: < script 类型 = text / javascript > $( function (){ $ .ajax({ type: POST, contentType : application / json; charset = utf-8, url: Default.aspx / BindDatatoDropdown, data: {}, dataType: json,成功: function (msg){ if (msg!= null ){ if (msg。 d!= null ){ $( #ddlLanguages)。append($( < option>< / option>).val( 0 )。html( 选择语言)); var Dropdown = $(' #< ;%= ddlLanguages.ClientID%>'); Dropdown.append( new 选项( SELECT语言, 0 )); var obj = JSON .parse(msg.d); $ .each(obj, function (i,d){ Dropdown.append(新选项(d.LanguageName,d.PkLanguageId)); $( #ddlLanguages)。append($( < option>< /选项>)。val(d.PkLanguageId).html(d.LanguageName)); }); } } },错误: function (结果){ alert( 错误); } }); $( #ddlLanguages)。change( function (){ alert($( #ddlLanguages )。val()); ddlLanguageChange($( #ddlLanguages )。val()); }); ddlLanguageChange = function (){ alert( 这里); postData = {}; $ .ajax({ async: false , type: POST, url: Default.aspx / ddlLanguageChange, data: JSON .stringify({ dbParameters:postData}), contentType: application / json; charset = utf-8, dataType: json ,成功: function (msg){ if (msg!= null ){ if (msg.d!= null ){ alert( B); var obj = JSON .parse(msg.d); $ .each(obj, function (i,d){ alert( B); }); if (msg.d == hi) { $( #ddlLanguages )。val()= 印地语; } else { $( #ddlLanguages)。val()= 英语 ; } } } },}); } }); < / script > < fieldset > < asp:DropDownList ID = ddlLanguages runat = server AutoPostBack = true onselectedindexchanged = ddlLanguages_SelectedIndexChanged > <% - < asp:ListItem Text =Select LanguageValue =0/> < asp:ListItem Text =EnglishValue =en/> < asp:ListItem Text =HindiValue =hi/> - %> <% - < triggers> < asp:asyncpostbacktrigger controlid =ddlLanguageseventname =ddlLanguages_SelectedIndexChanged/> < /触发器> - %> < / fieldset > 和代码 protected void ddlLanguages_SelectedIndexChanged( object sender,EventArgs e) { string language = ddlLanguages.SelectedValue.ToString(); int LanguageId; if (language == hi ) { LanguageId = 2 ; } 其他 { LanguageId = 1 ; } // switch(language) // { // caseen: // LanguageId = 1; // break; // casehi: // LanguageId = 2; // break; // 默认值: / / break; // } StateHandler.GetHandler(StateHandler.StateType.Session).Add(SessionKeys.Language,LanguageId); Thread.CurrentThread.CurrentCulture = new CultureInfo(language); Thread.CurrentThread.CurrentUICulture = new CultureInfo(language); ddlLanguages.SelectedIndex = -1; ddlLanguages.SelectedValue = language; } 解决方案 ( function ( ){ .ajax({ type: POST , contentType: application / json; charset = utf-8 , url: Default.aspx / BindDatatoDropdown, data: {}, dataType: json,成功: function (msg){ if (msg!= null ){ if (msg.d!= null ){ ( #ddlLanguages)。附加( I have a dropdownlist which is populated by jquery and dropdownlist has a autopostback event.I want to call a dropdownlist selected index changed event by jquery to add their values into session as per that make changes on the same pageWhat I have tried:<script type="text/javascript"> $(function () { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/BindDatatoDropdown", data: "{}", dataType: "json", success: function (msg) { if (msg != null) { if (msg.d != null) { $("#ddlLanguages").append($("<option></option>").val(0).html("Select Language")); var Dropdown = $('#<%=ddlLanguages.ClientID %>'); Dropdown.append(new Option("SELECT Language", 0)); var obj = JSON.parse(msg.d); $.each(obj, function (i, d) { Dropdown.append(new Option(d.LanguageName, d.PkLanguageId)); $("#ddlLanguages").append($("<option></option>").val(d.PkLanguageId).html(d.LanguageName)); }); } } }, error: function (result) { alert("Error"); } }); $("#ddlLanguages").change(function () { alert($("#ddlLanguages").val()); ddlLanguageChange ($("#ddlLanguages").val()); }); ddlLanguageChange = function () { alert("Here"); postData = {}; $.ajax({ async: false, type: "POST", url: "Default.aspx/ddlLanguageChange", data: JSON.stringify({ "dbParameters": postData }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg != null) { if (msg.d != null) { alert("B"); var obj = JSON.parse(msg.d); $.each(obj, function (i, d) { alert("B"); }); if(msg.d == "hi") { $("#ddlLanguages").val() = "Hindi"; } else { $("#ddlLanguages").val() = "English"; } } } }, }); } });</script> <fieldset> <asp:DropDownList ID="ddlLanguages" runat="server" AutoPostBack="true" onselectedindexchanged="ddlLanguages_SelectedIndexChanged"> <%--<asp:ListItem Text="Select Language" Value="0" /> <asp:ListItem Text="English" Value="en" /> <asp:ListItem Text="Hindi" Value="hi" />--%> <%--<triggers> <asp:asyncpostbacktrigger controlid="ddlLanguages" eventname="ddlLanguages_SelectedIndexChanged" /> </triggers>--%> </fieldset> and in codeprotected void ddlLanguages_SelectedIndexChanged(object sender, EventArgs e) { string language = ddlLanguages.SelectedValue.ToString(); int LanguageId; if (language == "hi") { LanguageId = 2; } else { LanguageId = 1; } //switch (language) //{ // case "en": // LanguageId = 1; // break; // case "hi": // LanguageId = 2; // break; // default: // break; //} StateHandler.GetHandler(StateHandler.StateType.Session).Add(SessionKeys.Language, LanguageId); Thread.CurrentThread.CurrentCulture = new CultureInfo(language); Thread.CurrentThread.CurrentUICulture = new CultureInfo(language); ddlLanguages.SelectedIndex = -1; ddlLanguages.SelectedValue = language; } 解决方案 (function () {.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/BindDatatoDropdown", data: "{}", dataType: "json", success: function (msg) { if (msg != null) { if (msg.d != null) {("#ddlLanguages").append( 这篇关于下拉列表的Onselectedindexchange事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 23:51