0

I'm trying to create a dynamic module where I drop an object on screen. Then a jQuery dialog opens with three drop-down lists. When I select a value in the first drop-down list I'm trying to filter the results in the next list via Ajax.

This is my JS code:

$("#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());
        }
   );

In the ASP.NET page I'm doing the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TableCodes.aspx.cs" Inherits="AjaxActions_TableCodes" %>

<form id="form1" runat="server">
     <asp:HiddenField ID="hidCodesList" runat="server" />
</form>

The code behind for this page:

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() + ",";
    }
}

}

In my first call to alert I get the entire page. In that I can see the hidden field filled with the data I need. How can i extract this data? Finally, all the drop-down lists are in a JDialog so maybe that is causing an issue.

4

1 回答 1

1

关于 ASP.NET jQuery 和级联下拉列表的一般答案

从我可以从您的问题中看出,您尝试创建的用户体验是一个模式弹出窗口(通过 jDialog),其中包含一系列级联下拉列表。有很多方法可以使用这种范式。使用搜索词“级联下拉列表 asp.net ”将为您提供很多关于如何将各种解决方案付诸实践的示例。

这里有几篇文章可能会有所帮助

更具体到您的问题

本质上,您想通过包含三个下拉列表的 jDialog 加载模式弹出窗口。您应该绑定到onchange第一个下拉菜单的事件。绑定函数应该使用 jQuery 调用 Web 方法,该方法返回数据以填充下一个下拉列表。

[编辑]
上面链接的文章(使用 jQuery 和 JSON 在 ASP.Net 中构建级联下拉列表)显示了如何通过 JSON 和 jQuery 对象的 append 方法将选项附加到下拉列表的示例。我已经提取了相关的附加代码。

$("#ddlCities").append($("<option></option>").val(this['ID']).html(this['City']));

[/编辑]

于 2010-10-02T19:17:34.800 回答