Critical Developers

Programmers Knowledge Base

Export Multiple GridView to Excel

Dim heading As String = ""
Dim heading1 As String = ""
heading = "<center><h1>All-Members</h1></center><br />"
Dim filename As String = "All-Grid-Details" & CStr(Date.Today.Day & Date.Today.ToString("MM") & Date.Today.Year) & ".xls"
Dim form As New HtmlForm()
GridView1.AllowPaging = False
BindGrid1()
GridView2.AllowPaging = False
BindGrid2()
GridView3.AllowPaging = False
BindGrid3()
GridView4.AllowPaging = False
BindGrid4()
GridView5.AllowPaging = False
BindGrid5()
Response.ClearContent()
Dim attachment As String = "attachment; filename=" & filename
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim stw As New StringWriter()
Dim htextw As New HtmlTextWriter(stw)
form.Controls.Add(Label1)
form.Controls.Add(GridView1)
form.Controls.Add(Label2)
form.Controls.Add(GridView2)
form.Controls.Add(Label3)
form.Controls.Add(GridView3)
form.Controls.Add(Label4)
form.Controls.Add(GridView4)
form.Controls.Add(Label5)
form.Controls.Add(GridView5)
Me.Controls.Add(form)
form.RenderControl(htextw)
Response.Write(heading)
Response.Write(stw.ToString())
Response.End()

Bind Files in DropDownList from Server


Bind Files in DropDownList from Server
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class banner : System.Web.UI.Page
{
    protected string dirPath;
    protected int dirPathLength;
    protected String[] files;
    public string strEmbed = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["bid"] != null)
            {
                getfilename();
            }
        }
    }

    public void getfilename()
    {
        ArrayList values = new ArrayList();
        dirPath = Server.MapPath("../banners/");
        dirPathLength = dirPath.Length;
        dirPathLength = dirPathLength + 1;
        files = Directory.GetFiles(dirPath, "*.*");
        for (int i = 0; i < files.Length; i++)
        {
            string FileName = files[i];
            FileName = FileName.Replace(Server.MapPath("../banners/"), "");
            values.Add(FileName);
        }
        ddlselect.DataSource = values;
        ddlselect.DataBind();
        ddlselect.Items.Insert(0, "--Select--");
    }
}