首页  ·  知识 ·  
Label
      编辑:  图片来源:网络
再谈 N 个 ASP.net DropDownList 无刷新联动菜单,牺牲N-1个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();  
   }
  }

本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信