Peaq Developer

Peaq Developer

  • NA
  • 130
  • 3.6k

My dropDownList always in insert take the fisrt value

Mar 4 2020 4:08 PM
My dropDownList Always take the first value when I change the value,insert the first this my code
 
public partial class AddUsers : System.Web.UI.Page
{
UsersLogique users = new UsersLogique();
RolesLogique Roles = new RolesLogique();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Users"] == null)
{
Response.Redirect("Authentication.aspx");
}
else
{
BindRoleList();
}
}
private void Insert()
{
try
{
var UEmail = Email.Text.ToString().Trim();
var UPassword = Password.Text.ToString().Trim();
var UFirstName = FirstName.Text.ToString().Trim();
var ULastName = LastName.Text.ToString().Trim();
var UIsDelete = 0;
var UCreation = DateTime.Now.ToString().Trim();
var UCreatedBy = Convert.ToInt32(Session["Users"]);
var URole = role.SelectedValue;
var User = new DataAccessLayer.Models.USER
{
UsersEmail = UEmail,
UsersPassword = UPassword,
UsersFirstName = UFirstName,
UsersLastName = ULastName,
IsDelete = Convert.ToBoolean(UIsDelete),
DateCreation = Convert.ToDateTime(UCreation),
IdRoles= Convert.ToInt32(URole),
CreatedBy = UCreatedBy,
};
users.CreateNewUser(User);
Response.Redirect("Users.aspx");
}
catch (Exception)
{
throw;
}
}
private void BindRoleList()
{
var roles = Roles.RolesList().ToList();
role.DataSource = roles.Select(a => new { a.RolesId, a.RolesName });
role.DataValueField = "RolesId";
role.DataTextField = "RolesName";
role.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
Insert();
}
}
}
 
 

Answers (1)