日期:2014-05-18 浏览次数:20860 次
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string name = this.dropdownlist.selectValue; BindView(string name); this.dataview.DataBind(); } public void BindView(string name) { if(s == "老师") { string="select * from 老师"; DataTable table = new DataTable(); /*然后把这个SQL语句查询到的数据绑定到table里面*/ this.gridview.datasouce = table; } else if(s == "学生") { string="select * from 学生"; DataTable table = new DataTable(); /*然后把这个SQL语句查询到的数据绑定到table里面*/ this.gridview.datasouce = table; } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> </head> <body> <form id="form1" runat="server"> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form> </body> </html>