- void BindGrid()
- {
- DataSet objds = "";
- GridView1.DataSource = objds;
- GridView1.DataBind();
- }
- void ExcelExport
- {
- Response.ClearContent();
- Response.Buffer = true;
- Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "UserDetails.xls"));
- Response.ContentType = "application/ms-excel";
- StringWriter sw = new StringWriter();
- HtmlTextWriter htw = new HtmlTextWriter(sw);
- gvAdminDetails.AllowPaging = false;
- BindGrid();
- //Change the Header Row back to white color
- Gridview1.HeaderRow.Style.Add("background-color", "#FFFFFF");
- //Applying stlye to gridview header cells
- for (int i = 0; i < gvAdminDetails.HeaderRow.Cells.Count; i++)
- {
- Gridview1.HeaderRow.Cells[i].Style.Add("background-color", "#F0F0F0");
- }
- int j = 1;
- //This loop is used to apply stlye to cells based on particular row
- foreach (GridViewRow gvrow in gvAdminDetails.Rows)
- {
- gvrow.BackColor = System.Drawing.Color.White;
- if (j <= Gridview1.Rows.Count)
- {
- if (j % 2 != 0)
- {
- for (int k = 0; k < gvrow.Cells.Count; k++)
- {
- gvrow.Cells[k].Style.Add("background-color", "#F0F0F0");
- }
- }
- }
- j++;
- }
- Gridview1.RenderControl(htw);
- Response.Write(sw.ToString());
- Gridview1.AllowPaging = true;
- Response.End();
- }
- public override void VerifyRenderingInServerForm(Control control)
- {
- //required to avoid the runtime error "
- //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
- }
Monday, 2 January 2017
Gridview Excel Export In C#
Subscribe to:
Post Comments (Atom)
Getting Available Server Disk Space (Total Size / Free Space) SQL Query
SELECT distinct(volume_mount_point), total_bytes/1048576 as Size_in_MB, total_bytes/1048576/1024 as Size_in_GB, available_bytes/1048576 ...

-
CREATE TAblE #temp ( T_Name VARCHAR(50), T_Times BIGINT ) INSERT INTO #temp(T_Name,T_Times) VALUES ('ASHISH',4) IN...
-
# Find Largest Element of an Array using Function # python function to find maximum # in arr[] of size n def largest(arr,n): # Initi...
-
Model: public class M_MenuModel { #region Variable public Int32 MMID { get; set; } public string MM_N...

No comments:
Post a Comment