62,040
社区成员
发帖
与我相关
我的任务
分享
// 后台
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "";
if(this.DropDownList1.SelectedIndex == 1)
{
sql = "SELECT * FROM [表名] WHERE [step]=1";
}
else
{
sql = "SELECT * FROM [表名] WHERE [step]=2";
}
// 去数据库查数据
// 此处省略n行代码...
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select * from table where step='" + this.DropDownList1.SelectedValue + "'";
//传入数据库返回数据。
DataTable dt = ReturnDataTable(sql);
}
public static DataTable ReturnDataTable(string cmdtext)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "数据库连接字符串";
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand(cmdtext, cn);
cmd.CommandType = CommandType.Text; ;
SqlDataReader dr = null;
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
return dt;
}