1000 pts datagrid to excel with columns readonly

Discussion in 'ASP .Net' started by Luis Esteban Valencia, Jan 7, 2005.

  1. Here is my aspx code:
    =============
    <%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false"
    Inherits="PDM.excel.WebForm3" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm3</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body text="black" bgColor="silver" MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px;
    POSITION: absolute; TOP: 72px" runat="server"
    GridLines="Vertical" AutoGenerateColumns="False"
    CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None"
    BorderColor="#E7E7FF">
    <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7"
    BackColor="#738A9C"></SelectedItemStyle>
    <AlternatingItemStyle
    BackColor="#F7F7F7"></AlternatingItemStyle>
    <ItemStyle ForeColor="#4A3C8C"
    BackColor="#E7E7FF"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7"
    BackColor="#4A3C8C"></HeaderStyle>
    <FooterStyle ForeColor="#4A3C8C"
    BackColor="#B5C7DE"></FooterStyle>
    <Columns>
    <asp:BoundColumn DataField="string_id"
    ReadOnly="true" HeaderText="String ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="string" ReadOnly="true"
    HeaderText="String"></asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Center" ForeColor="Black"
    BackColor="#999999" Mode="NumericPages"></PagerStyle>
    </asp:datagrid><asp:dropdownlist id="Language_DropDownList"
    style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 24px"
    runat="server"
    AutoPostBack="True"></asp:dropdownlist><asp:label id="Label1"
    style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 24px"
    runat="server"
    Width="248px" Font-Bold="True">Choose Your Language To
    Convert:</asp:label><asp:button id="Button1" style="Z-INDEX: 104; LEFT:
    392px; POSITION: absolute; TOP: 24px" runat="server"
    Text="Submit"></asp:button></form>
    </body>
    </HTML>


    and asp.cs
    ======
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Xml.Xsl;
    using System.Xml;

    namespace PDM.excel
    {
    /// <summary>
    /// Summary description for WebForm3.
    /// </summary>
    public class WebForm3 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    public SqlConnection conDB = new SqlConnection();

    static public string[] LanguageStr =
    {
    "English","French","Spanish"};
    static public string[] DropDownListStr =
    {
    "Language_DropDownList"};
    protected System.Web.UI.WebControls.DropDownList
    Language_DropDownList;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Button Button1;

    static public string[][] AddStrArray =
    {
    LanguageStr};

    private void Fill_DropDownList()
    {
    for (int i = 0; i < DropDownListStr.Length; i++)
    {
    string CtrlName= DropDownListStr;
    DropDownList MyList =
    (DropDownList)Page.FindControl(CtrlName);
    // Populate all the checkboxes
    string[] ToPopulate = AddStrArray;
    for (int j = 0; j < ToPopulate.Length; j++)
    {
    MyList.Items.Add(new ListItem(ToPopulate[j],
    j.ToString()));
    }
    }
    }

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    if(!Page.IsPostBack)
    {
    Fill_DropDownList();


    }

    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form
    Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Language_DropDownList.SelectedIndexChanged += new
    System.EventHandler(this.Language_DropDownList_SelectedIndexChanged);
    this.Button1.Click += new
    System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    public DataSet DataToExcel = new DataSet();



    public void BindGrid (int index)
    {
    conDB.ConnectionString = "data
    source=10.195.17.7;database=devnew;uid=bounaajak;pwd=ehsfirst;packet
    size=4096";
    SqlDataAdapter da = new SqlDataAdapter("Select string_id,
    string from pdm_translations where language_id = 1 and string_id not in
    (select string_id from pdm_translations where language_id = " +
    index.ToString() + ") ", conDB);
    da.Fill(DataToExcel, "DataToExcel");
    Session["Tabla"] = Language_DropDownList.SelectedItem.Text;
    DataToExcel.WriteXml(Server.MapPath(Session["Tabla"] +
    ".xml"));
    DataGrid1.DataSource = DataToExcel;
    DataGrid1.DataBind();
    // Get row count
    int nRowCount = DataToExcel.Tables["DataToExcel"].Rows.Count;
    // Store Row count in Session variable
    Session["RowCount"] = nRowCount;


    }
    private void Language_DropDownList_SelectedIndexChanged(object
    sender, System.EventArgs e)
    {
    int getSelectedIndex = Language_DropDownList.SelectedIndex+1;
    BindGrid(getSelectedIndex);

    }

    public void DataGridToExcel(DataGrid Export,HttpResponse Response)
    {

    // Set the Response mime type for excel
    Response.ContentType = "application/vnd.ms-excel";
    // Create a String Writer
    System.IO.StringWriter stringWrite = new
    System.IO.StringWriter();
    Response.Charset = "";
    this.EnableViewState = false;
    System.IO.StringWriter tw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter hw = new
    System.Web.UI.HtmlTextWriter(tw);
    DataGrid1.RenderControl(hw);
    Response.Write(tw.ToString());
    Response.End();

    }

    private void Button1_Click(object sender, System.EventArgs e)
    {
    DataGridToExcel (DataGrid1, Response);
    }




    }
    }

    --
    LUIS ESTEBAN VALENCIA
    MICROSOFT DCE 3.
    MIEMBRO ACTIVO DE ALIANZADEV
    http://spaces.msn.com/members/extremed/
    Luis Esteban Valencia, Jan 7, 2005
    #1
    1. Advertising

  2. Luis Esteban Valencia

    Raterus Guest

    http://www.experts-exchange.com/Pro...Languages/Dot_Net/ASP_DOT_NET/Q_21265758.html

    :)

    "Luis Esteban Valencia" <> wrote in message news:...
    > Here is my aspx code:
    > =============
    > <%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false"
    > Inherits="PDM.excel.WebForm3" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>WebForm3</title>
    > <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > </HEAD>
    > <body text="black" bgColor="silver" MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px;
    > POSITION: absolute; TOP: 72px" runat="server"
    > GridLines="Vertical" AutoGenerateColumns="False"
    > CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None"
    > BorderColor="#E7E7FF">
    > <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7"
    > BackColor="#738A9C"></SelectedItemStyle>
    > <AlternatingItemStyle
    > BackColor="#F7F7F7"></AlternatingItemStyle>
    > <ItemStyle ForeColor="#4A3C8C"
    > BackColor="#E7E7FF"></ItemStyle>
    > <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7"
    > BackColor="#4A3C8C"></HeaderStyle>
    > <FooterStyle ForeColor="#4A3C8C"
    > BackColor="#B5C7DE"></FooterStyle>
    > <Columns>
    > <asp:BoundColumn DataField="string_id"
    > ReadOnly="true" HeaderText="String ID"></asp:BoundColumn>
    > <asp:BoundColumn DataField="string" ReadOnly="true"
    > HeaderText="String"></asp:BoundColumn>
    > </Columns>
    > <PagerStyle HorizontalAlign="Center" ForeColor="Black"
    > BackColor="#999999" Mode="NumericPages"></PagerStyle>
    > </asp:datagrid><asp:dropdownlist id="Language_DropDownList"
    > style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 24px"
    > runat="server"
    > AutoPostBack="True"></asp:dropdownlist><asp:label id="Label1"
    > style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 24px"
    > runat="server"
    > Width="248px" Font-Bold="True">Choose Your Language To
    > Convert:</asp:label><asp:button id="Button1" style="Z-INDEX: 104; LEFT:
    > 392px; POSITION: absolute; TOP: 24px" runat="server"
    > Text="Submit"></asp:button></form>
    > </body>
    > </HTML>
    >
    >
    > and asp.cs
    > ======
    > using System;
    > using System.Collections;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Web;
    > using System.Web.SessionState;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    > using System.Data.SqlClient;
    > using System.Xml.Xsl;
    > using System.Xml;
    >
    > namespace PDM.excel
    > {
    > /// <summary>
    > /// Summary description for WebForm3.
    > /// </summary>
    > public class WebForm3 : System.Web.UI.Page
    > {
    > protected System.Web.UI.WebControls.DataGrid DataGrid1;
    > public SqlConnection conDB = new SqlConnection();
    >
    > static public string[] LanguageStr =
    > {
    > "English","French","Spanish"};
    > static public string[] DropDownListStr =
    > {
    > "Language_DropDownList"};
    > protected System.Web.UI.WebControls.DropDownList
    > Language_DropDownList;
    > protected System.Web.UI.WebControls.Label Label1;
    > protected System.Web.UI.WebControls.Button Button1;
    >
    > static public string[][] AddStrArray =
    > {
    > LanguageStr};
    >
    > private void Fill_DropDownList()
    > {
    > for (int i = 0; i < DropDownListStr.Length; i++)
    > {
    > string CtrlName= DropDownListStr;
    > DropDownList MyList =
    > (DropDownList)Page.FindControl(CtrlName);
    > // Populate all the checkboxes
    > string[] ToPopulate = AddStrArray;
    > for (int j = 0; j < ToPopulate.Length; j++)
    > {
    > MyList.Items.Add(new ListItem(ToPopulate[j],
    > j.ToString()));
    > }
    > }
    > }
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > if(!Page.IsPostBack)
    > {
    > Fill_DropDownList();
    >
    >
    > }
    >
    > }
    >
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > //
    > // CODEGEN: This call is required by the ASP.NET Web Form
    > Designer.
    > //
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > this.Language_DropDownList.SelectedIndexChanged += new
    > System.EventHandler(this.Language_DropDownList_SelectedIndexChanged);
    > this.Button1.Click += new
    > System.EventHandler(this.Button1_Click);
    > this.Load += new System.EventHandler(this.Page_Load);
    >
    > }
    > #endregion
    >
    > public DataSet DataToExcel = new DataSet();
    >
    >
    >
    > public void BindGrid (int index)
    > {
    > conDB.ConnectionString = "data
    > source=10.195.17.7;database=devnew;uid=bounaajak;pwd=ehsfirst;packet
    > size=4096";
    > SqlDataAdapter da = new SqlDataAdapter("Select string_id,
    > string from pdm_translations where language_id = 1 and string_id not in
    > (select string_id from pdm_translations where language_id = " +
    > index.ToString() + ") ", conDB);
    > da.Fill(DataToExcel, "DataToExcel");
    > Session["Tabla"] = Language_DropDownList.SelectedItem.Text;
    > DataToExcel.WriteXml(Server.MapPath(Session["Tabla"] +
    > ".xml"));
    > DataGrid1.DataSource = DataToExcel;
    > DataGrid1.DataBind();
    > // Get row count
    > int nRowCount = DataToExcel.Tables["DataToExcel"].Rows.Count;
    > // Store Row count in Session variable
    > Session["RowCount"] = nRowCount;
    >
    >
    > }
    > private void Language_DropDownList_SelectedIndexChanged(object
    > sender, System.EventArgs e)
    > {
    > int getSelectedIndex = Language_DropDownList.SelectedIndex+1;
    > BindGrid(getSelectedIndex);
    >
    > }
    >
    > public void DataGridToExcel(DataGrid Export,HttpResponse Response)
    > {
    >
    > // Set the Response mime type for excel
    > Response.ContentType = "application/vnd.ms-excel";
    > // Create a String Writer
    > System.IO.StringWriter stringWrite = new
    > System.IO.StringWriter();
    > Response.Charset = "";
    > this.EnableViewState = false;
    > System.IO.StringWriter tw = new System.IO.StringWriter();
    > System.Web.UI.HtmlTextWriter hw = new
    > System.Web.UI.HtmlTextWriter(tw);
    > DataGrid1.RenderControl(hw);
    > Response.Write(tw.ToString());
    > Response.End();
    >
    > }
    >
    > private void Button1_Click(object sender, System.EventArgs e)
    > {
    > DataGridToExcel (DataGrid1, Response);
    > }
    >
    >
    >
    >
    > }
    > }
    >
    > --
    > LUIS ESTEBAN VALENCIA
    > MICROSOFT DCE 3.
    > MIEMBRO ACTIVO DE ALIANZADEV
    > http://spaces.msn.com/members/extremed/
    >
    >
    Raterus, Jan 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VmlqYXk=?=

    Parser Error Message: Could not load type 'PTS.Global'.

    =?Utf-8?B?VmlqYXk=?=, May 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,446
    Brock Allen
    May 25, 2005
  2. pozz
    Replies:
    27
    Views:
    707
    Seebs
    Mar 4, 2011
  3. Jonathan Hyatt
    Replies:
    1
    Views:
    1,844
    Jonathan Hyatt
    Jun 8, 2004
  4. Todd Gardner
    Replies:
    2
    Views:
    93
    Todd Gardner
    Jun 21, 2004
  5. Alexander Newald

    Open /dev/pts/x or HANDLE read/write interactive?

    Alexander Newald, Jan 15, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    606
    Tad McClellan
    Jan 15, 2004
Loading...

Share This Page