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

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

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

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航