Example #1
0
    protected void CancelRow_Click(object sender, EventArgs e)
    {
        // Response.Redirect(Request.RawUrl);
        GridViewuhierchymad.DataSource = SqlDataSourcegridvalue;

        GridViewuhierchymad.DataBind();
    }
Example #2
0
    private void RetriveData()
    {
        GridViewuhierchymad.DataSource = SqlDataSourcegridvalue;
        GridViewuhierchymad.DataBind();


        //string constr = ConfigurationManager.ConnectionStrings["esspconnection"].ConnectionString;
        //using (SqlConnection conn = new SqlConnection(constr))
        //{

        //    using (SqlCommand cmd = new SqlCommand("procviewhierchypostwise"))
        //    {
        //        cmd.CommandType = CommandType.StoredProcedure;
        //        cmd.Parameters.AddWithValue("@username", Session["username"].ToString());


        //        using (SqlDataAdapter sda = new SqlDataAdapter())
        //        {
        //            cmd.Connection = conn;
        //            sda.SelectCommand = cmd;
        //            using (DataTable dt = new DataTable())
        //            {
        //                sda.Fill(dt);
        //                GridViewuhierchymad.DataSource = dt;
        //                GridViewuhierchymad.DataBind();
        //                //Calculate Sum and display in Footer Row
        //                //decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("Stock Value"));
        //                //Grid_stockdetails.FooterRow.Cells[9].Text = "Total";
        //               // Grid_stockdetails.FooterRow.Cells[9].HorizontalAlign = HorizontalAlign.Right;
        //                //Grid_stockdetails.FooterRow.Cells[10].Text = total.ToString("N2");

        //            }
        //        }
        //    }
        //}
    }
Example #3
0
    protected void exportbtn_Click(object sender, EventArgs e)
    {
        if (GridViewuhierchymad.Rows.Count != 0)
        {
            Response.Clear();
            Response.Buffer = true;
            //Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            //Response.AppendHeader("content-disposition", "attachment; filename=GridViewExport.xlsx");

            Response.AddHeader("content-disposition", "attachment;filename=Uiversal_Hierarchy_MAD" + DateTime.Now.Date + ".xls");
            Response.Charset = "";

            Response.ContentType = "application/vnd.ms-excel";

            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages



                foreach (GridViewRow row in GridViewuhierchymad.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        //cell.CssClass = "textmode";
                        List <Control> controls = new List <Control>();

                        //Add controls to be removed to Generic List
                        foreach (Control control in cell.Controls)
                        {
                            controls.Add(control);
                        }

                        //Loop through the controls to be removed and replace then with Literal
                        foreach (Control control in controls)
                        {
                            switch (control.GetType().Name)
                            {
                            case "HyperLink":
                                cell.Controls.Add(new Literal {
                                    Text = (control as HyperLink).Text
                                });
                                break;

                            case "Label":
                                cell.Controls.Add(new Literal {
                                    Text = (control as Label).Text
                                });
                                break;

                            case "TextBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as TextBox).Text
                                });
                                break;

                            case "LinkButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as LinkButton).Text
                                });
                                break;

                            case "CheckBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as CheckBox).Text
                                });
                                break;

                            case "RadioButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as RadioButton).Text
                                });
                                break;

                            case "FileUpload":
                                cell.Controls.Add(new Literal {
                                    Text = (control as FileUpload).HasFile.ToString()
                                });
                                break;

                            case "DropDownList":
                                cell.Controls.Add(new Literal {
                                    Text = (control as DropDownList).SelectedValue
                                });
                                break;
                            }
                            cell.Controls.Remove(control);
                        }
                    }
                }

                GridViewuhierchymad.RenderControl(hw);
                GridViewuhierchymad.Columns.RemoveAt(0);
                //style to format numbers to string
                string style = @"<style> .textmode { mso-number-format:\@; } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }
    }