如何使用 jQuery 和 Ajax 仅返回一个字符串以及如何将其插入到 jdialog 中的 DDL 中?
我正在尝试创建一个动态模块,将一个对象放在屏幕上。然后将打开一个 jQuery 对话框,其中包含三个下拉列表。当我在第一个下拉列表中选择一个值时,我尝试通过 Ajax 过滤下一个列表中的结果。
这是我的 JS 代码:
$("#ddlTableType").live(
'change',
function()
{
var GetTablesCodes = $.ajax({
url:'AjaxActions/TableCodes.aspx?ObjectType=' + $("#ddlTableType").val(),
async:false
}).responseText;
//alert(GetTablesCodes);
//alert(GetTablesCodes.$('#hidCodesList').val());
//alert($('#hidCodesList').val());
}
);
在 ASP.NET 页面中,我正在执行以下操作:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TableCodes.aspx.cs" Inherits="AjaxActions_TableCodes" %>
<form id="form1" runat="server">
<asp:HiddenField ID="hidCodesList" runat="server" />
</form>
此页面背后的代码:
public partial class AjaxActions_TableCodes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet dsCodesList = DbHelper.ExecuteDataSet(
ConfigurationManager.AppSettings["ConnStr"],
"spObjectCodesByTYpe_Select",
new SqlParameter("@ObjectType", Request.QueryString["ObjectType"])
);
hidCodesList.Value = "";
for(Int16 CodeListIndex=0;CodeListIndex<dsCodesList.Tables[0].Rows.Count;CodeListIndex++)
{
hidCodesList.Value += dsCodesList.Tables[0].Rows[CodeListIndex]["Value"].ToString() + ",";
}
}
}
在第一次调用警报时,我获得了整个页面。我可以看到隐藏字段填充了我需要的数据。我怎样才能提取这些数据?最后,所有下拉列表都在 JDialog 中,因此这可能会导致问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于 ASP.NET jQuery 和级联下拉列表的一般答案
从我可以从您的问题中看出,您尝试创建的用户体验是一个模式弹出窗口(通过 jDialog),其中包含一系列< em>级联下拉列表。有很多方法可以使用这个范例。使用搜索词“级联下拉列表asp.net”将为您提供大量关于如何将各种解决方案付诸实践的示例。
这里有几篇文章可能会有所帮助
更具体地解决您的问题
本质上,您希望通过 jDialog 加载一个模式弹出窗口,其中包含三个下拉列表。您应该绑定到第一个下拉列表的
onchange
事件。绑定函数应使用 jQuery 调用 Web 方法,该方法返回数据以填充下一个下拉列表。[编辑]
上面链接的文章(使用 jQuery 和 JSON 在 ASP.Net 中构建级联 DropDownList )显示了如何通过 JSON 和 jQuery 对象的追加方法将选项附加到下拉列表的示例。我已经提取了相关的附加代码。
[/编辑]
General Answer on ASP.NET jQuery and Cascading Drop-down lists
From what I can discern from your question the user experience you are trying to create is a modal popup (via jDialog) which contains a series of cascading drop-down lists. There are quite a few ways to put this paradigm into use. Using the search terms "cascading drop-down lists asp.net" will net you a lot of examples on how to put the various solutions into practice.
Here are a couple of articles which may help
More Specific to your problem
Essentially you want to load a modal popup via jDialog which contains three drop-down lists. You should bind to the
onchange
event of the first drop-downs. The bound function should use jQuery to call a web method which returns the data to fill the next drop-down.[edit]
The article linked above (Building Cascading DropDownList in ASP.Net Using jQuery and JSON) shows an example of how to append options to a drop-down list via JSON and the append method of a jQuery object. I've pulled out the pertinent append code.
[/edit]