473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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/
Nov 19 '05 #1
1 1839
http://www.experts-exchange.com/Prog..._21265758.html

:-)

"Luis Esteban Valencia" <lu*******@haceb.com> wrote in message news:e8**************@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/

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ronny Sigo | last post by:
Hello all, As one of a few ways to let a user bring in data into my database I have made 3 excel files. Once the data are in the excel files my program checks if a required value (Taal (Dutch)...
0
by: Rudolph Araujo | last post by:
Hi, I needed to build a data grid in which the first column has hyperlinks rather than simple text. I found the following code on this newsgroup and it works fine except for one problem. When I...
4
by: | last post by:
I have a datagrid with a template column that has a hyperlink and a label. The hyperlink text is bound to Title from my dataset and the label text is bound to Author in the dataset. The grid...
0
by: R Corona | last post by:
I am creating a datagrid that has four columns. I am creating the first, an edit column and the last in the html of the page. The middle two are being added in the code behind. One is a readonly...
1
by: steve | last post by:
Hi, I have generated a datagrid with the following columns: | Date-Time | Station ID | Parameter1 | .... | Parameter 2| I would like to: Create an Excel file and preferably give the user...
4
by: Ohad Weiss | last post by:
Hi all I need to know weather it is possible to add a column to a datagrig that based on a dataset, which is not in the dataset (like a description of a code that appear in the datagrid). ...
3
by: chnadeem | last post by:
i am using VB.Net 2003 and i have made an application using datagrid. i have displayed data in data grid from the database. i want that 1st two columns remain readonly and remaing can be edited. plz...
1
by: Mike G | last post by:
I have a datagrid that is editable by the user. Some of the columns are readonly and others can be edited. I have one column that I need to be able to make readonly based on the values of other...
1
by: adarshyam | last post by:
Hi, I am trying to import contents of excel spread sheet to the panel of textboxes (NOT datagrid). can anybody please tel me how to import the contents of each cell in the column into the textboxes...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.