110,536
社区成员
发帖
与我相关
我的任务
分享
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string name = this.dropdownlist.selectValue;
BindView(name);
this.dataview.DataBind();
}
<%@ 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>
<%@ 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 s = DropDownList1.SelectedValue;
if(s == "老师")
{
string="select * from 老师";
DataTable table = new DataTable();
/*然后把这个SQL语句查询到的数据绑定到table里面*/
this.gridview.datasouce = table;
this.gridview.databind();
}
else if(s == "学生")
{
string="select * from 学生";
DataTable table = new DataTable();
/*然后把这个SQL语句查询到的数据绑定到table里面*/
this.gridview.datasouce = table;
this.gridview.databind();
}
}
</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>