熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

N個ASP.net DropDownList 無刷新聯動菜單

2013-11-13 10:06:27  來源: .NET編程 

  再談 N 個 DropDownList 無刷新聯動菜單犧牲N個ASPX來實現自動更新機制避免刷新的閃動!!

  以下代碼絕對可以使用也可以實現多級菜單

  

  ============================

  webform1.aspx

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此處放置用戶代碼以初始化頁面
   if(!IsPostBack)
   {
    SqlConnection con = new SqlConnection("packet size=4096;user id=sa;data source=SERVER;persist security info=False;initial catalog=pubs");
    SqlDataAdapter da = new SqlDataAdapter("select state from authors group by state",con);
    DataSet ds = new DataSet("State");
    da.Fill(ds);
    this.DropDownList1.DataSource = ds.Tables[0];
    this.DropDownList1.DataTextField = "state";
    this.DropDownList1.DataValueField = "state"; 
    this.DropDownList1.DataBind();  
    this.DropDownList1.Attributes.Add("onchange","load()");  
    //DropDownList1.
   }
 
  }

  webform2.aspx

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此處放置用戶代碼以初始化頁面
   if(this.Request["state"]!=null)
   {  
    string state = this.Request["state"].ToString();  
    SqlConnection con = new SqlConnection("packet size=4096;user id=sa;data source=SERVER;persist security info=False;initial catalog=pubs");
    SqlDataAdapter da = new SqlDataAdapter("select address from authors where state = '"+state+"'",con);  
    DataSet ds = new DataSet("address");  
    da.Fill(ds);  
    XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);  
    writer.Formatting = Formatting.Indented;  
    writer.Indentation = 4;  
    writer.IndentChar = ' ';  
    ds.WriteXml(writer);  
    writer.Flush();  
    Response.End();  
    writer.Close();  
   }
  }


From:http://tw.wingwit.com/Article/program/net/201311/12577.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.