-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManageUser.aspx.cs
95 lines (85 loc) · 2.94 KB
/
ManageUser.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
print();
}
public void print()
{
SqlDataAdapter adpt = new SqlDataAdapter("SELECT [id], [fullname], [email], [password] FROM [Users]", con);
DataTable dt = new DataTable();
adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
public void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Button btn = (Button)sender;
SqlCommand cmd = new SqlCommand("DELETE FROM [Users] WHERE [id] = @id", con);
cmd.Parameters.AddWithValue("@id", btn.CommandArgument);
con.Open();
int s = cmd.ExecuteNonQuery();
con.Close();
if (s == 1)
{
Literal1.Text = "User Delete Successfully";
print();
}
else
{
Literal1.Text = "Error";
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
SqlDataAdapter adpt = new SqlDataAdapter("SELECT [id], [fullname], [email], [password] FROM [Users] WHERE [id] ="+btn.CommandArgument, con);
DataTable dt = new DataTable();
adpt.Fill(dt);
TextBox1.Text = dt.Rows[0][1].ToString();
TextBox2.Text = dt.Rows[0][2].ToString();
TextBox3.Text = dt.Rows[0][3].ToString();
ViewState["user_id"] = btn.CommandArgument;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("UPDATE [Users] SET [fullname] = @fullname, [email] = @email, [password] = @password WHERE [id] = @id", con);
cmd.Parameters.AddWithValue("@fullname", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@email", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@id", ViewState["user_id"]);
con.Open();
int s = cmd.ExecuteNonQuery();
con.Close();
if (s == 1)
{
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
Literal1.Text = "Update successfully ";
print();
}
else
{
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
}
}
}