TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/NewsAndEvents.aspx.cs

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 NewsAndEvents : 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();


            DataSet dd = obj.getDataSet(@"SELECT  ROW_NUMBER() OVER (ORDER BY Id desc) AS Sno, Name, Status
                FROM [tbl_NewsEvent] Order by ID desc");
            
            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 = obj.ExcuteCommand("INSERT INTO [tbl_NewsEvent]([Name], [Link]) "
                + " VALUES('" + txtNews.Text.Trim() + "', '" + txtLink.Text.Trim() + "')");

            obj.CloseConnection();
            if (x>0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully');", true);
                ShowNewsDetails();
                txtNews.Text = "";
                txtLink.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, Link, Status
                FROM [tbl_NewsEvent] 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, Link, Status
                FROM [tbl_NewsEvent] 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;
            }

            if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
            {
                TextBox txtLink = (TextBox)e.Row.FindControl("txtLink");
                string Link = DataBinder.Eval(e.Row.DataItem, "Link").ToString();
                txtLink.Text = Link;
            }
        }

        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 Link = (GridView.Rows[e.RowIndex].FindControl("txtLink") 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_NewsEvent SET Status = '" + Status + "', Name ='" + Name + "'" 
                    + ", link='" + Link +"' WHERE ID = " + _ID);
                lblUpdate.Text = "Record updated successfully.";
                Response.Redirect(Request.Url.AbsoluteUri);
            }
            else
            {
                obj.ExcuteCommand("delete tbl_NewsEvent 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