TechEthical CEHP
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Directory;
using System.Data;
using System.Data.SqlClient;
namespace Bathuasoft.admin
{
public partial class CourseEntryOld : System.Web.UI.Page
{
public System.Data.DataTable dt = new System.Data.DataTable();
public System.Data.SqlClient.SqlDataAdapter SqlAdapter = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
connection_sql obj = new connection_sql();
obj.MakeConnection();
if (!IsPostBack)
{
if (Session["Loginxtr"].ToString() != "1254lkjhhfdgftfrdgf")
{
Response.Redirect("login.aspx");
}
PopulateDS(); // FILL DATASET WITH MASTER DATA.
ShowNewsDetails(); // SHOW EMPLOYEE DETAILS IN THE GRIDVIEW.
}
}
protected void butSave_Click(object sender, EventArgs e)
{
connection_sql obj = new connection_sql();
obj.MakeConnection();
int x = 0;
try
{
x= obj.ExcuteCommand("INSERT INTO [tbl_Courses] ([Name], Status) "
+ " VALUES('" + txtName.Text.Trim() + "', 'Active')");
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('" + ex.Message +"');", true);
}
obj.CloseConnection();
if (x > 0)
{
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully');", true);
ShowNewsDetails();
txtName.Text = "";
}
}
// CANCEL ROW EDITING.
protected void GridView_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
{
GridView.EditIndex = -1;
ShowNewsDetails();
}
// ROW EDITING
protected void GridView_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
ShowNewsDetails();
lblUpdate.Text = "";
}
private void PopulateDS()
{
dt.Clear();
connection_sql obj = new connection_sql();
obj.MakeConnection();
dt = obj.getDataTable(@"SELECT ROW_NUMBER() OVER (ORDER BY Name) AS 'Sr No', ID, Name, Status
FROM [tbl_Courses] order by id ");
}
private void ShowNewsDetails()
{
dt.Clear();
connection_sql obj = new connection_sql();
obj.MakeConnection();
dt = obj.getDataTable(@"SELECT ROW_NUMBER() OVER (ORDER BY ID) AS 'Sr No', ID, Name, Status
FROM [tbl_Courses] order by id desc");
GridView.DataSource = dt;
GridView.DataBind();
obj.CloseConnection();
}
protected void GridView_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
DropDownList drpStatus = (DropDownList)e.Row.FindControl("drpStatus");
string SelectedText = DataBinder.Eval(e.Row.DataItem, "Status").ToString();
drpStatus.Items.FindByText(SelectedText).Selected = true;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtName = (TextBox)e.Row.FindControl("txtName");
string Text = DataBinder.Eval(e.Row.DataItem, "Name").ToString();
txtName.Text = Text;
}
}
protected void UpdateStatus(object sender, GridViewUpdateEventArgs e)
{
string Status = (GridView.Rows[e.RowIndex].FindControl("drpStatus") as DropDownList).SelectedItem.Text;
string Name = (GridView.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text;
string _ID = GridView.DataKeys[e.RowIndex].Value.ToString();
connection_sql obj = new connection_sql();
obj.MakeConnection();
if (Status != "Delete")
{
obj.ExcuteCommand("UPDATE tbl_Courses SET Status = '" + Status + "', Name ='" + Name + "'"
+ " WHERE ID = " + _ID);
lblUpdate.Text = "Record updated successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
obj.ExcuteCommand("delete tbl_Courses WHERE ID = " + _ID);
lblUpdate.Text = "Record has been delete successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
ShowNewsDetails();
}
}
}
}
TechEthical Mini WebShell Version 1.0, Coded By The_M@T3