首页 > 编程 > .NET > 正文

N个ASP.net dropDownList 无刷新联动菜单

2024-07-10 13:11:56
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

  再谈 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();  
   }
  }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表