<tr>
                    <td class="bqleft">
                        <asp:TextBox ID="TextBox11" runat="server" Style="display: none">news</asp:TextBox>
                        类型:</td>
                    <td class="bqright">
                        <asp:DropDownList  ID="DropDownList6" runat="server" Height="16px" Width="83px">
                            <asp:ListItem Value="1">--旺铺--</asp:ListItem>
                            <asp:ListItem Value="2">--写字楼--</asp:ListItem>
                            <asp:ListItem Value="3">--招商引资--</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList ID="DropDownList5" runat="server" Height="16px" Width="86px">                           
                            
                        </asp:DropDownList>
                        </td>
                </tr>  初始化DropDownList5 if (!IsPostBack)
        {
            ViewState["retu"] = Request.UrlReferrer.ToString();
            DropDownList5.DataTextField = "typename";
            DropDownList5.DataValueField = "id";
            DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
            DropDownList5.DataBind();      
        }DropDownList6的change事件$(document).ready(function () {    $("#DropDownList6").change(function () {
        $.ajax({
            type: "post",
            url: "../../ASHX/type.ashx",
            data: { father_id: $("#DropDownList6").val() },
            success: function (data) {                          
                $("#DropDownList5").html(data);
            }, error: function () {
                alert("发生未知错误!请联系管理员!");
            }
        });
    });
});一般处理程序   type.ashxpublic void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Charset = "gbk";
        int father_id = 1;
        
        if (!string.IsNullOrEmpty(context.Request["father_id"]))
        {
            father_id = Convert.ToInt32(context.Request["father_id"]);
            string sql = "select * from hddtype where father_id=" + father_id + " order by id asc";
            DataTable dt = Common.GetKyCms(sql);
            string htmltext = string.Empty;
            bool isfirst = true;
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (isfirst)
                    {
                        htmltext += "<option value=\"" + row[0].ToString() + "\" selected=\"selected\">" + row[1] + "</option>";
                        isfirst = false;
                    }
                    else
                        htmltext += "<option value=\"" + row[0].ToString() + "\">" + row[1] + "</option>";
                }
            }
            context.Response.Write(htmltext.ToString());
            context.Response.End();   //结束流   
        }   
    }

解决方案 »

  1.   

    是选择DropDownList6的时候,DropDownList5的值出现相应的变化,能出现效果。但是在保存的时候总是出现  这个绑定的第一个值。这是什么原因呢?我调试了好久。 success: function (data) {                          
                    $("#DropDownList5").html(data);   //我觉得是不是异步提交的时候出现了问题。
                },  DropDownList5.DataTextField = "typename";
                DropDownList5.DataValueField = "id";
                DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
                DropDownList5.DataBind();      
      

  2.   

    能出现级联的效果,但是在保存的时候DropDownList5的值总是  DropDownList5.DataTextField = "typename";
                DropDownList5.DataValueField = "id";
                DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
                DropDownList5.DataBind();      的第一个值。很奇怪
      

  3.   

    你分析的对如果你想 dropdownlist5 的值,可以把dropdownlist5 加一个客户端的 onclick事件执行onclick事件的时候,把dropdownlist5的值存入hidden控件。在后台你想得到dropdownlist5的值的时候,直接使用hidden控件的值,就可以了
      

  4.   

    恩,这个想法不错。我没想到,我开始也用的是onclick事件。但是也获取不到值,
    看来可以用hidden。
      

  5.   

    dropdownlist5 应该是它的SelectedIndexChanged 事件吧  姐姐
      

  6.   

    这种方法是有问题的,
    加入我选择dropdownlist6但是直接保存的话,hidden就是为空了,呵呵。
    除非我在dropdownlist5前面加个“请选择”