TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/Category.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 Directory.admin
{
          public partial class WebForm3 : 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)
        {

            if (Session["Loginxtr"].ToString() != "1254lkjhhfdgftfrdgf")
            {
                Response.Redirect("login.aspx");
            }

            connection_sql obj = new connection_sql();
            obj.MakeConnection();


            DataSet dd = obj.getDataSet(@"SELECT  ROW_NUMBER() OVER (ORDER BY Id) AS Sno, Name, Status
                FROM [tblCategory] ");
            
            if (!IsPostBack)
            {
       
                PopulateDS();        // FILL DATASET WITH MASTER DATA.
                ShowCategoryDetails();    // SHOW EMPLOYEE DETAILS IN THE GRIDVIEW.
            }

        }

        protected void category_mgt_Click(object sender, EventArgs e)
        {

           connection_sql obj = new connection_sql();
            obj.MakeConnection();

           
            DataTable ds = obj.getDataTable(@"SELECT  * FROM[dbo].[tblCategory] ORDER BY ID DESC");

           // ds.Rows[0]["Id"].ToString();

            int x=obj.ExcuteCommand ("INSERT INTO [dbo].[tblCategory]([Name])VALUES('" + txt_cat.Text.Trim() + "')");



           // int y = obj.ExcuteCommand("INSERT INTO [dbo].[tbl_Subcategory]([category_Id])VALUES('" + ds.Rows[0]["Id"].ToString() + "')");

            obj.CloseConnection();
            if (x>0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully');", true);
            }
            
        }
   

   
    // CANCEL ROW EDITING.
    protected void GridView_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
        {
            GridView.EditIndex = -1;
            ShowCategoryDetails();
        }



        // ROW EDITING
        protected void GridView_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            GridView.EditIndex = e.NewEditIndex;
            ShowCategoryDetails();
            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 [tblCategory] order by Name ");
        }

        private void ShowCategoryDetails()
        {
            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 [tblCategory] order by Name ");

            GridView.DataSource = dt;
            GridView.DataBind();
        }

        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 xstrCategory = (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();
            obj.ExcuteCommand("UPDATE tblCategory SET Status = '" + Status + "', Name ='" + xstrCategory + "'  WHERE ID = " + _ID);
            lblUpdate.Text = "Record updated successfully.";
            Response.Redirect(Request.Url.AbsoluteUri);
        }
    }


}


TechEthical Mini WebShell Version 1.0, Coded By The_M@T3