TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
271
36k
show grid view on select of admin from dropdown list asp.net C# E.F
Jul 22 2020 6:33 AM
dear Experts,
how could i display all users when i select Admin from my dropdown and i am using entity framework..
here is my code..
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<header id=
"header"
>
<div
class
=
"intro text-center"
>
<div
class
=
"overlay"
>
<div
class
=
"container"
>
<div
class
=
"row"
>
<div
class
=
"intro-text"
>
<h1> <span
class
=
"brand"
>Registration</span></h1>
</div>
</div>
</div>
</div>
</div>
</header>
<table
class
=
"style1"
>
<tr>
<td> Image:</td>
<td>
<asp:FileUpload ID=
"TxtImg"
runat=
"server"
></asp:FileUpload>
</td>
</tr>
<tr>
<td> Name:</td>
<td>
<asp:TextBox ID=
"TxtName"
runat=
"server"
></asp:TextBox>
</td>
<asp:RequiredFieldValidator ID=
"RequiredFieldValidator1"
runat=
"server"
Style=
"top:182px; left: 774px; position: absolute; height: 26px; width: 162px"
ControlToValidate=
"TxtName"
ErrorMessage=
"Name required**"
font-size=
"Small"
ForeColor =
"Red"
></asp:RequiredFieldValidator>
</tr>
<tr>
<td>UserName:</td>
<td>
<asp:TextBox ID=
"TxtUserName"
runat=
"server"
></asp:TextBox>
</td>
<asp:RequiredFieldValidator ID=
"RequiredFieldValidator2"
runat=
"server"
Style=
"top: 224px; left: 774px; position: absolute; height: 26px; width: 162px"
ControlToValidate=
"TxtUserName"
ErrorMessage=
"Username required** "
font-size=
"Small"
ForeColor=
"Red"
></asp:RequiredFieldValidator>
</tr>
<tr>
<td>EmailID:</td>
<td>
<asp:TextBox ID=
"TxtEmailID"
runat=
"server"
></asp:TextBox>
</td>
<asp:RequiredFieldValidator ID=
"RequiredFieldValidator3"
runat=
"server"
Style=
"top:271px; left: 774px; position: absolute; height: 26px; width: 162px"
ControlToValidate=
"TxtEmailID"
ErrorMessage=
"Valid EmailID required"
font-size=
"Small"
ForeColor=
"Red"
></asp:RequiredFieldValidator>
</tr>
<tr>
<td>UserRole:</td>
<td>
<asp:DropDownList ID=
"DdlUser"
runat=
"server"
>
<asp:ListItem Value =
"0"
>---Select Role--</asp:ListItem>
<asp:ListItem >--- Admin--</asp:ListItem>
<asp:ListItem>---User--</asp:ListItem>
<asp:ListItem >---EndUser--</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox ID=
"TxtPassword"
runat=
"server"
TextMode=
"Password"
></asp:TextBox>
</td>
<asp:RequiredFieldValidator ID=
"RequiredFieldValidator5"
runat=
"server"
TextMode=
"Password"
Style=
"top:321px; left: 774px; position: absolute; height: 26px; width: 162px"
ControlToValidate=
"TxtPassword"
ErrorMessage=
"It contains 1-special character and 0-9 numbers required"
font-size=
"Small"
ForeColor=
"Red"
></asp:RequiredFieldValidator>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBox ID=
"TxtConfirmPassword"
runat=
"server"
TextMode=
"Password"
></asp:TextBox> </td>
</tr>
<tr>
<td>
<asp:Label ID=
"LblMesge"
runat=
"server"
></asp:Label>
</td>
<td> </td>
</tr>
</table>
</div>
<asp:Button ID=
"Button1"
runat=
"server"
Text=
"Save"
class
=
"btn"
onclick=
"Button1_Click"
/>
</form>
</body>
Aspx code::
public
partial
class
WebForm2 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Model.User newusermodel =
new
Model.User();
newusermodel.Image = TxtImg.ToString();
newusermodel.Name = TxtName.Text;
newusermodel.UserName = TxtUserName.Text;
newusermodel.EmailID = TxtEmailID.Text;
newusermodel.Created_Date = DateTime.Now;
newusermodel.User_Role = DdlUser.SelectedValue.ToString();
newusermodel.User_Type_Id = 3;
newusermodel.Password = TxtPassword.Text;
using
(WallpaperEntities4 context =
new
WallpaperEntities4())
{
User user =
new
User();
{
string
str = TxtImg.FileName;
TxtImg.PostedFile.SaveAs(Server.MapPath(
"~/Upload/"
+ str));
string
Image =
"~/Upload/"
+ str.ToString();
string
name = TxtImg.ToString();
user.Image = newusermodel.Image;
user.Name = newusermodel.Name;
user.UserName = newusermodel.UserName;
user.EmailID = newusermodel.EmailID;
user.User_Role = newusermodel.User_Role;
user.Created_Date = newusermodel.Created_Date;
user.User_Type_Id = newusermodel.User_Type_Id;
user.Password = newusermodel.Password;
};
var usersadd = context.Set<User>();
var response = context.Users.Where(u => u.UserName == newusermodel.UserName).FirstOrDefault();
if
(response ==
null
)
{
usersadd.Add(user);
context.SaveChanges();
Response.Redirect(
"/Login.aspx"
);
}
else
{
LblMesge.Text =
"User exists"
;
}
}
}
}
Reply
Answers (
2
)
How to get the first Data in JavaScript
Appending comma in given number