-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteAgency.aspx.cs
112 lines (99 loc) · 3.41 KB
/
DeleteAgency.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
public partial class DeleteAgency : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(
WebConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack)
{
if ((Session["AdEmailID"] == null))
{ Response.Redirect("Default.aspx"); }
else
{
HyperLink login = (HyperLink)Master.FindControl("login");
login.Text = "Manage Agency";
login.Visible = false;
// login.NavigateUrl = "Account.aspx";
HyperLink reg = (HyperLink)Master.FindControl("register");
reg.Visible = false;
HyperLink home = (HyperLink)Master.FindControl("home");
home.NavigateUrl = "AdminHome.aspx";
BindGrid();
}
}
}
private void BindGrid()
{
con.Open();
//string email = Session["AEmailID"].ToString();
//SqlCommand cmd4 = new SqlCommand("Select * from Employee + "'", con);
//int aid = Convert.ToInt32(cmd4.ExecuteScalar());
using (SqlCommand cmd = new SqlCommand("Select * from Agency"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
deleteAgency.DataSource = dt;
deleteAgency.DataBind();
con.Close();
}
}
}
}
protected void btnstatus_Click(object sender, EventArgs e)
{
Button clickedbutton = (Button)sender; //get clicked button
GridViewRow row = (GridViewRow)clickedbutton.NamingContainer; //get the row where the button clicked
int ind = row.RowIndex;
string id = deleteAgency.DataKeys[ind].Value.ToString();
Button btstatus = row.FindControl("btnstatus") as Button;
string status = btstatus.Text;
int newstat = 0;
if (status == "Activate")
{
status = "Deactivate";
newstat = 1;
}
else if (status == "Deactivate")
{
status = "Activate";
newstat = 0;
}
// update record
SqlCommand cmd = new SqlCommand("update Agency set Status='" + newstat + "'where AgencyID=" + id, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}
protected void deleteAgency_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
deleteAgency.PageIndex = e.NewPageIndex;
//Bind data to the GridView control.
BindGrid();
}
protected void deleteAgency_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
deleteAgency.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
BindGrid();
}
protected void deleteAgency_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
deleteAgency.EditIndex = -1;
BindGrid();
}
}