Hello all, Somebody please help me by modifying this code.In my login page i have three column Login,UserName,Password.In Login i have kept dropdownlist with two list item Admin and User.So when i Select Admin,UserName,Password it should go to desired destination page and when i select User,UserName,Password it should go to another desired destination page.Here is my code. please help me......
Login.aspx:
<asp:Label ID="lblLogin" runat="server" Text="Login" CssClass="Label"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Admin</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblUserName" runat="server" Text="User Name"</asp:Label>
<asp:TextBox ID="TxtUserName" runat="server" TextMode="SingleLine"></asp:TextBox>
<asp:Label ID="lblPassword" runat="server" Text="Password" CssClass="Label"></asp:Label>
<asp:TextBox ID="TxtPassword" runat="server" TextMode="Password"></asp:TextBox>
<td align="center">
<asp:Button ID="BtnLogin" runat="server" Text="Login"
onclick="BtnLogin_Click"/>
Login.aspx.cs:
protected void BtnLogin_Click(object sender, EventArgs e)
{
Session["UserName"] = TxtUserName.Text;
Login lg = new Login();
if ((lg.GetLogin(TxtUserName.Text, TxtPassword.Text) == 1))
{
Response.Redirect("c1.aspx");
}
else
{
Lbl1.Text = "Sorry,Invalid UserName or Password";
}
Login.cs:
public class Login
{ public string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
public int GetLogin(string UserName, string Password)
{
SqlConnection con = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("select * from Login where UserName='"+UserName+"' and Password='"+Password+"'",con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if ((ds.Tables[0].Rows[0].ItemArray[1].ToString() == UserName) && (ds.Tables[0].Rows[0].ItemArray[2].ToString() == Password))
{
return 1;
}
else
{
return 0;
}
}
else
{
return -1;
}
}
Thanks, Masum