Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   1000 pts datagrid to excel with columns readonly (http://www.velocityreviews.com/forums/t94046-1000-pts-datagrid-to-excel-with-columns-readonly.html)

Luis Esteban Valencia 01-07-2005 04:58 PM

1000 pts datagrid to excel with columns readonly
 
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[i];
DropDownList MyList =
(DropDownList)Page.FindControl(CtrlName);
// Populate all the checkboxes
string[] ToPopulate = AddStrArray[i];
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_Sel ectedIndexChanged);
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;p wd=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 01-07-2005 05:10 PM

Re: 1000 pts datagrid to excel with columns readonly
 
http://www.experts-exchange.com/Prog..._21265758.html

:-)

"Luis Esteban Valencia" <luisvalen@haceb.com> wrote in message news:e89WuoN9EHA.1524@TK2MSFTNGP09.phx.gbl...
> 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[i];
> DropDownList MyList =
> (DropDownList)Page.FindControl(CtrlName);
> // Populate all the checkboxes
> string[] ToPopulate = AddStrArray[i];
> 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_Sel ectedIndexChanged);
> 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;p wd=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/
>
>



All times are GMT. The time now is 02:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.