C#以下语句DropDownList1 只认"学生"表 这是为什么?

来源:百度知道 编辑:UC知道 时间:2024/05/10 10:47:57
protected void btnOK_Click(object sender, EventArgs e)
{
int i = 0;
SqlConnection con = new SqlConnection("Server=(local);database=db_pingjiao;Uid=sa;Pwd=");
switch (i)
{
case 0:
{
DropDownList1.Text = "学生";
SqlDataAdapter da1 = new SqlDataAdapter("select * from student where name='" + txtUid.Text + "'and pwd='" + txtPwd.Text + "'", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
Response.Write("<script>alert('登录成功!!!')</script>");
}
else
{
Response.Write("<script>alert(&

你那样设置值不对,应该这样:
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText( "教务人员"));

此外你的
int i = 0; 表示你的i始终是0当然只是‘学生’啦