Tuesday, 20 June 2017

View_CustomerDetail .cs page

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;
using System.Data.Sql;

namespace Customer_Detail
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        String strConnString = ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString;
        private const string ASCENDING = " ASC";
        private const string DESCENDING = " DESC";
        SqlConnection con;
        DataTable dt = null;
        public string GetConnectionString()
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //DisplayRecord();
                bindGrid();
            }
        }

        public void bindGrid()
        {
           
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_GetCustomerDetails";
            cmd.Parameters.Add("@firstname", SqlDbType.NVarChar).Value = txtfname.Text.Trim();
            cmd.Parameters.Add("@lastname", SqlDbType.NVarChar).Value = txtlname.Text.Trim();
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
             dt = new DataTable();
            da.Fill(dt);
            ViewState["Paging"] = dt;
            try
            {
                con.Open();
                gvdisplay.EmptyDataText = "No Records Found";
                gvdisplay.DataSource = dt;
                gvdisplay.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }

        public void DisplayRecord()
        {
            try
            {
                SqlConnection conn = new SqlConnection(GetConnectionString());
                string com = "Select customerID,firstname +'" + " " + "'+ lastname as Name,dob,department,designation,contactno,email,IsActive from addcustomer";
                SqlDataAdapter adpt = new SqlDataAdapter(com, conn);
                DataTable dt = new DataTable();
                adpt.Fill(dt);
                gvdisplay.DataSource = dt;
                gvdisplay.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }

        //public void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        //{
        //    GridViewRow row = (GridViewRow)gvdisplay.Rows[e.RowIndex];
        //    Label lbldeleteid = (Label)row.FindControl("");
        //    con.Open();
        //    SqlCommand cmd = new SqlCommand("delete FROM detail where customerID='" + Convert.ToInt32(gvdisplay.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
        //    cmd.ExecuteNonQuery();
        //    con.Close();
        //    bindGrid();
        //}

        //public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        //{
        //    gvdisplay.EditIndex = e.NewEditIndex;
        //    bindGrid();
        //}

        //public void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        //    int customerid = Convert.ToInt32(gvdisplay.DataKeys[e.RowIndex].Value.ToString());
        //    string department = ddldepartment.SelectedItem.Text;
        //    GridViewRow row = (GridViewRow)gvdisplay.Rows[e.RowIndex];
        //    Label lblID = (Label)row.FindControl("lblID");
        //    //TextBox txtname=(TextBox)gr.cell[].control[];
        //    TextBox textName = (TextBox)row.Cells[0].Controls[0];
        //    TextBox textadd = (TextBox)row.Cells[1].Controls[0];
        //    TextBox textc = (TextBox)row.Cells[2].Controls[0];
        //    //TextBox textadd = (TextBox)row.FindControl("txtadd");
        //    //TextBox textc = (TextBox)row.FindControl("txtc");
        //    gvdisplay.EditIndex = -1;
        //    con.Open();
        //    //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
        //    SqlCommand cmd = new SqlCommand("update detail set firstname='" + txtfname.Text + "',lastname='" + txtlname.Text + "',department='" + department + "' where customerID='" + customerid + "'", con);
        //    cmd.ExecuteNonQuery();
        //    con.Close();
        //    bindGrid();
        //    //gvdisplay.DataBind();
        //}

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            bindGrid();
        }

        public void gridpaging(object sender, GridViewPageEventArgs e)
        {
            gvdisplay.PageIndex = e.NewPageIndex;
            gvdisplay.DataSource = ViewState["Paging"];
            gvdisplay.DataBind();
        }

        public SortDirection CurrentSortDirection
        {
            get
            {
                if (ViewState["SortDirection"] == null)
                {
                    ViewState["SortDirection"] = SortDirection.Ascending;
                }
                return (SortDirection)ViewState["SortDirection"];
            }
            set
            {
                ViewState["SortDirection"] = value;
            }
        }

        public void Gridsorting(object sender, GridViewSortEventArgs e)
        {
            string ColumnTosort = e.SortExpression;

            if (CurrentSortDirection == SortDirection.Ascending)
            {
                CurrentSortDirection = SortDirection.Descending;
                SortGridView(ColumnTosort, DESCENDING);
            }
            else
            {
                CurrentSortDirection = SortDirection.Ascending;
                SortGridView(ColumnTosort, ASCENDING);
            }

        }

        private void SortGridView(string sortExpression, string direction)
        {
            dynamic dt = ViewState["Paging"];
            DataTable dtsort = dt;
            DataView dv = new DataView(dtsort);
            dv.Sort = sortExpression + direction;

            gvdisplay.DataSource = dv;
            gvdisplay.DataBind();
        }

        protected void gvdisplay_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int customerid = Convert.ToInt32(gvdisplay.DataKeys[e.RowIndex].Value.ToString());
            //string department = ddldepartment.SelectedItem.Text;
            GridViewRow row = (GridViewRow)gvdisplay.Rows[e.RowIndex];
            Label lblID = (Label)row.FindControl("lblID");
            //TextBox txtname=(TextBox)gr.cell[].control[];
            TextBox textName = (TextBox)row.Cells[1].Controls[0];
            string[] name = textName.Text.Split(null);
            TextBox txtdepartment = (TextBox)row.Cells[2].Controls[0];
            TextBox txtdesignation = (TextBox)row.Cells[3].Controls[0];
            TextBox txtdob = (TextBox)row.Cells[4].Controls[0];
            TextBox txtcontactno = (TextBox)row.Cells[5].Controls[0];
            TextBox txtemail = (TextBox)row.Cells[6].Controls[0];
            //TextBox textadd = (TextBox)row.FindControl("txtadd");
            //TextBox textc = (TextBox)row.FindControl("txtc");
            gvdisplay.EditIndex = -1;

            SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
            SqlCommand cmd = new SqlCommand("update addcustomer set firstname='" + name[0] + "',lastname='" + name[1] + "',department='" + txtdepartment.Text + "', designation='" + txtdesignation.Text + "', dob='" + txtdob.Text +"', contactno='" + txtcontactno.Text +"', email='" + txtemail.Text + "'  where customerID='" + customerid + "'", con);
            cmd.ExecuteNonQuery();
            con.Close();
            bindGrid();
            //gvdisplay.DataBind();
        }

        protected void gvdisplay_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvdisplay.EditIndex = e.NewEditIndex;
            bindGrid();
        }

        protected void gvdisplay_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = (GridViewRow)gvdisplay.Rows[e.RowIndex];
            Label lbldeleteid = (Label)row.FindControl("");
            SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            SqlCommand cmd = new SqlCommand("delete FROM addcustomer where customerID='" + Convert.ToInt32(gvdisplay.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
            cmd.ExecuteNonQuery();
            con.Close();
            bindGrid();
        }
    }

}

RAJESH GAMI - Blog

How to show number with two decimal places in AngularJS 1.0

How to show number with two decimal places in AngularJS 1.0 Introduction:             Here   solution of display number with 2 deci...