asp.net求助
总出这个错误:行 22: {
行 23: //接收用户输入的参数
行 24: string userName = txtUserName.Text.ToString().Trim();
行 25: string userPwd = txtPwd.Text.ToString().Trim();
行 26: string userRole = rblClass.SelectedValue.Trim();
原文://文件名:Login.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class System_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e)
{
//接收用户输入的参数
string userName = txtUserName.Text.ToString().Trim();
string userPwd = txtPwd.Text.ToString().Trim();
string userRole = rblClass.SelectedValue.Trim();
string selectStr = "";
switch (userRole)
{
case "0": //身份为员工时
selectStr = "Select * from aspnet-Membership where UserId = '" + userName + "'";
break;
case "1": //身份为管理员时
selectStr = "Select * from guanliyuan where name = '" + userName + "'";
break;
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(selectStr, conn);
try
{
conn.Open(); //打开连接
SqlDataReader sdr = cmd.ExecuteReader(); //执行查询
if (sdr.Read()) //如果该用户存在
{
if (sdr.GetString(1) == userPwd) //密码正确
{
Session["userName"] = userName;
Session["userRole"] = userRole;
conn.Close();
switch (userRole)
{
case "0": //身份为员工时
Response.Redirect("TeacherQueryElect.aspx");
break;
case "1": //身份为管理员时
Response.Redirect("stuClsTable.aspx");
break;
}
}
else //密码错误,给出提示信息!
{
lblMessage.Text = "您输入的密码错误,请检查后重新输入!";
}
}
else //用户不存在或用户名输入错误
{
lblMessage.Text = "该用户不存在或用户名输入错误,请检查后重新输入!";
}
}
catch (Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
}
}
可是.aspx文件中可是找到txtUserName,txtPwd,rblClass,lblMessage这些的,请高手指点一下,谢谢
--------------------编程问答-------------------- 你自己看看你的提问,你觉得你能明白吗? --------------------编程问答-------------------- 把 string userRole = rblClass.SelectedValue.Trim(); 改成
string userRole = rblClass.SelectedItem.Value();试试看
以后尽量把你所遇到的问题描述清楚一点,好让大家一起帮你解决 --------------------编程问答-------------------- 谢谢
补充:.NET技术 , C#