博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ajax dropdownlist联动

Posted on 2008-06-27 18:16  小飞龙(Jack)  阅读(567)  评论(0编辑  收藏  举报
<table width="100%" cellpadding="0" cellspacing="0" border="0">
                                        <tr>
                                            <td align="right" width="17%">
                                                <asp:Label ID="Label4" runat="server" Text="科室:"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlDept" runat="server" Width="65px" onchange="load()">
                                                </asp:DropDownList>
                                                <input id="Button1" type="button" value="选择" onclick="openWin_Sel()" />
                                            </td>
                                            <td align="right" width="20%">
                                                <asp:Label ID="Label7" runat="server" Text="医生:"></asp:Label>
                                            </td>
                                            <td width="25%">
                                                <asp:DropDownList ID="ddlDoctor" runat="server" Width="65px">
                                                    <asp:ListItem Value="">请选择</asp:ListItem>
                                                </asp:DropDownList>
                                                <input id="Button2" type="button" value="选择" onclick="openWin_Sel()" />
                                            </td>
                                        </tr>
                                    </table>

function load()
         {
            var DeptID = document.getElementById("ddlDept").value;
            var ddlDoctor=document.getElementById("ddlDoctor");
            ddlDoctor.options.length=1;//清空医生
            var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
            var oDoc = new ActiveXObject("MSXML2.DOMDocument");
            oHttpReq.open("POST", "ddlSel.aspx?DeptID="+DeptID, false);
           
            oHttpReq.send("");
          result = oHttpReq.responseText;
          oDoc.loadXML(result); 
         
           var newOption;
            for(var i=0;i<oDoc.firstChild.childNodes.length;i++)
            {
                newOption = document.createElement("OPTION");
                newOption.value = oDoc.firstChild.childNodes[i].childNodes[1].text;
                newOption.text = oDoc.firstChild.childNodes[i].childNodes[2].text;
                ddlDoctor.options.add(newOption);
            }
         }


ddlSel.aspx页
aspx.cs

public partial class ddlSel : System.Web.UI.Page
    {
        private string sesHID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            sesHID = Session["HospitalID"].ToString();
            if (Request.QueryString["DeptID"] != null)
            {
                string DeptID = Request.QueryString["DeptID"].ToString();
                DataTable dt = new DataTable();
                ArrayList AL = new ArrayList();
                AL.Add("res.Dept='" + DeptID + "'");
                AL.Add("sch_doc.HospitalID='" + sesHID + "'");
                dt = BLL.Regist.Regist_Appoint.GetDoctorInfo(AL);
                XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
                writer.Formatting = Formatting.Indented;
                writer.Indentation = 4;
                writer.IndentChar = ' ';
                dt.WriteXml(writer);
                writer.Flush();
                Response.End();
                writer.Close();

            }
        }
    }