コード例 #1
0
 /// <summary>
 /// Method Name:BtnRecords_Click
 /// Description:Display Records After Sorting Parameter Selected by User
 /// Author:Bhumi
 /// Created On:25/6/2015
 /// </summary>
 protected void BtnRecords_Click(object sender, EventArgs e)
 {
     try
     {
         //Sorting According to Dropdownlist Selection
         //Datacontext from LINQ Class
         Dtcontext = new DataContext(ConfigurationManager.ConnectionStrings["LINQ_ConnectionString"].ConnectionString);
         //Table from LINQ Class
         Emptbl = Dtcontext.GetTable <EmployeeDetail>();
         //Store the value of Sorting Parameter Selected by User using Dropdownlist
         SortParameter = ddlSort.SelectedItem.Text;
         if (SortParameter == "Name")
         {
             SortColumn = SortParameter;
             ShowData();
         }
         else if (SortParameter == "Address")
         {
             SortColumn = SortParameter;
             ShowData();
         }
         else if (SortParameter == "Email")
         {
             SortColumn = SortParameter;
             ShowData();
         }
         else if (SortParameter == "Salary")
         {
             SortColumn = SortParameter;
             ShowData();
         }
         else
         {
             objconstant = new ConstantMessages();
             ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('" + objconstant.stralertSortBy + "');", true);
         }
     }
     catch (Exception)
     {
         objconstant = new ConstantMessages();
         Response.Redirect(objconstant.strErrorPage);
     }
     finally
     {
         dt_emp      = null;
         objconstant = null;
         Emptbl      = null;
         row         = null;
     }
 }
コード例 #2
0
        /// <summary>
        /// Method Name:Page_Load
        /// Description:Sorting in Gridview using header row
        /// Author:Bhumi
        /// Created On:24/6/2015
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (ViewState["Employeetable"] == null)
                {
                    //Datacontext from LINQ Class
                    Dtcontext = new DataContext(ConfigurationManager.ConnectionStrings["LINQ_ConnectionString"].ConnectionString);
                    //Table from LINQ Class
                    Emptbl = Dtcontext.GetTable <EmployeeDetail>();

                    dt_emp.Columns.Add("Name");
                    dt_emp.Columns.Add("Address");
                    dt_emp.Columns.Add("Email");
                    dt_emp.Columns.Add("Salary", typeof(decimal));
                    var query = from i in Emptbl
                                select new { i.Name, i.Address, i.Email, i.Salary };
                    // Create a table from the query.
                    foreach (var rowObj in query)
                    {
                        row = dt_emp.NewRow();
                        dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                    }
                    //Datasource and binding to Gridview
                    if (dt_emp == null)
                    {
                        LblEmpty.Visible = true;
                    }
                    else
                    {
                        gvEmployeeDetails.DataSource = dt_emp;
                        gvEmployeeDetails.DataBind();
                        ViewState["Employeetable"] = dt_emp;
                    }
                }
            }
            catch (Exception)
            {
                objconstant = new ConstantMessages();
                Response.Redirect(objconstant.strErrorPage);
            }
            finally
            {
                objconstant = null;
            }
        }
コード例 #3
0
 /// <summary>
 /// Method Name:gvEmployeeDetails_Sorting
 /// Description:Sorting in Gridview
 /// Author:Bhumi
 /// Created On:24/6/2015
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void gvEmployeeDetails_Sorting(object sender, GridViewSortEventArgs e)
 {
     try
     {
         string SortDireaction = ViewState["_sortDirection"] as string; //Store Sorting Operation in Viewstate
         SetSortDirection(SortDireaction);                              //Call Method
         if (ViewState["Employeetable"] != null)
         {
             //Sort the data.
             dt_emp = ((DataTable)ViewState["Employeetable"]);
             dt_emp.DefaultView.Sort      = e.SortExpression + " " + _sortDirection;
             gvEmployeeDetails.DataSource = dt_emp;
             gvEmployeeDetails.DataBind();
             SortDireaction = _sortDirection;
             ViewState["_sortDirection"] = SortDireaction;
             //Checking the HeaderRow Cells where to put sorting image
             foreach (DataControlFieldHeaderCell headerCell in gvEmployeeDetails.HeaderRow.Cells)
             {
                 if (headerCell.ContainingField.SortExpression == e.SortExpression)
                 {
                     columnIndex = gvEmployeeDetails.HeaderRow.Cells.GetCellIndex(headerCell);
                 }
             }
             gvEmployeeDetails.HeaderRow.Cells[columnIndex].Controls.Add(sortImage);//ADD Image on Header Cell
             string sortExpression = e.SortExpression;
             ViewState["SearchSort"]    = sortExpression;
             ViewState["SortDirection"] = _sortDirection;
         }
     }
     catch (Exception)
     {
         objconstant = new ConstantMessages();
         Response.Redirect(objconstant.strErrorPage);
     }
     finally
     {
         dt_emp      = null;
         objconstant = null;
     }
 }
コード例 #4
0
 /// <summary>
 /// Method Name:ShowData
 /// Description:Datasource & Databinding with Control and set the Paging Feature code
 /// Author:Bhumi
 /// Created On:25/6/2015
 /// </summary>
 public void ShowData()
 {
     try
     {
         //Datacontext from LINQ Class
         Dtcontext = new DataContext(ConfigurationManager.ConnectionStrings["LINQ_ConnectionString"].ConnectionString);
         //Table from LINQ Class
         Emptbl = Dtcontext.GetTable <EmployeeDetail>();
         if (Emptbl == null)
         {
             LblEmpty.Visible = true;//No Records
         }
         else
         {
             if (SortColumn == null || SortColumn == "--SELECT--")
             {
                 dt_emp = new DataTable();
                 dt_emp.Columns.Add("Name");
                 dt_emp.Columns.Add("Address");
                 dt_emp.Columns.Add("Email");
                 dt_emp.Columns.Add("Salary");
                 var queryDefault = from i in Emptbl
                                    select new { i.Name, i.Address, i.Email, i.Salary };
                 foreach (var rowObj in queryDefault)
                 {
                     row = dt_emp.NewRow();
                     dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                 }
             }
             else
             {
                 if (SortColumn == "Name")
                 {
                     dt_emp = new DataTable();
                     dt_emp.Columns.Add("Name");
                     dt_emp.Columns.Add("Address");
                     dt_emp.Columns.Add("Email");
                     dt_emp.Columns.Add("Salary");
                     string SortVar   = SortColumn;
                     var    querySort = from i in Emptbl
                                        orderby i.Name ascending
                                        select new { i.Name, i.Address, i.Email, i.Salary };
                     // Create a table from the query.
                     foreach (var rowObj in querySort)
                     {
                         row = dt_emp.NewRow();
                         dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                     }
                 }
                 if (SortColumn == "Address")
                 {
                     dt_emp = new DataTable();
                     dt_emp.Columns.Add("Name");
                     dt_emp.Columns.Add("Address");
                     dt_emp.Columns.Add("Email");
                     dt_emp.Columns.Add("Salary");
                     string SortVar   = SortColumn;
                     var    querySort = from i in Emptbl
                                        orderby i.Address ascending
                                        select new { i.Name, i.Address, i.Email, i.Salary };
                     // Create a table from the query.
                     foreach (var rowObj in querySort)
                     {
                         row = dt_emp.NewRow();
                         dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                     }
                 }
                 if (SortColumn == "Email")
                 {
                     dt_emp = new DataTable();
                     dt_emp.Columns.Add("Name");
                     dt_emp.Columns.Add("Address");
                     dt_emp.Columns.Add("Email");
                     dt_emp.Columns.Add("Salary");
                     string SortVar   = SortColumn;
                     var    querySort = from i in Emptbl
                                        orderby i.Email ascending
                                        select new { i.Name, i.Address, i.Email, i.Salary };
                     // Create a table from the query.
                     foreach (var rowObj in querySort)
                     {
                         row = dt_emp.NewRow();
                         dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                     }
                 }
                 if (SortColumn == "Salary")
                 {
                     dt_emp = new DataTable();
                     dt_emp.Columns.Add("Name");
                     dt_emp.Columns.Add("Address");
                     dt_emp.Columns.Add("Email");
                     dt_emp.Columns.Add("Salary");
                     string SortVar   = SortColumn;
                     var    querySort = from i in Emptbl
                                        orderby i.Salary ascending
                                        select new { i.Name, i.Address, i.Email, i.Salary };
                     // Create a table from the query.
                     foreach (var rowObj in querySort)
                     {
                         row = dt_emp.NewRow();
                         dt_emp.Rows.Add(rowObj.Name, rowObj.Address, rowObj.Email, rowObj.Salary);
                     }
                 }
             }
             //Code for Paging Facility For Data controls
             pgd = new PagedDataSource();
             //Datasource for page
             pgd.DataSource       = dt_emp.DefaultView;
             pgd.CurrentPageIndex = CurrentPageIndex;//Assign Current Page Index
             pgd.AllowPaging      = true;
             pgd.PageSize         = 5;
             //Enable Disable & Visible or not for Next Pre Buttons
             LBtnNext.Enabled = !(pgd.IsLastPage);
             if (!(pgd.IsLastPage))
             {
                 LBtnNext.Visible = true;
             }
             if (pgd.IsFirstPage)
             {
                 LBtnPre.Visible = false;
             }
             LBtnPre.Enabled = !(pgd.IsFirstPage);
             if (!(pgd.IsFirstPage))
             {
                 LBtnPre.Visible = true;
             }
             if (pgd.IsLastPage)
             {
                 LBtnNext.Visible = false;
             }
             //Label Text for Total and Current Page
             LblCurrent.Text = (CurrentPageIndex + 1).ToString();
             LblTotal.Text   = (pgd.PageCount).ToString();
             //Databinding
             RptEmpDetails.DataSource = pgd;
             RptEmpDetails.DataBind();
             DlEmpDetails.DataSource = pgd;
             DlEmpDetails.DataBind();
         }
     }
     catch (Exception)
     {
         objconstant = new ConstantMessages();
         Response.Redirect(objconstant.strErrorPage);
     }
     finally
     {
         dt_emp      = null;
         objconstant = null;
         Emptbl      = null;
         row         = null;
         pgd         = null;
     }
 }
コード例 #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     objconstant = new ConstantMessages();
     Response.Write(objconstant.strErrormessage);
 }