473,624 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

1000 pts datagrid to excel with columns readonly

Here is my aspx code:
=============
<%@ Page language="c#" Codebehind="Web Form3.aspx.cs" AutoEventWireup ="false"
Inherits="PDM.e xcel.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="C#" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</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="Vert ical" AutoGenerateCol umns="False"
CellPadding="3" BackColor="Whit e" BorderWidth="1p x" BorderStyle="No ne"
BorderColor="#E 7E7FF">
<SelectedItemSt yle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#738 A9C"></SelectedItemSty le>
<AlternatingIte mStyle
BackColor="#F7F 7F7"></AlternatingItem Style>
<ItemStyle ForeColor="#4A3 C8C"
BackColor="#E7E 7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#4A3 C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3 C8C"
BackColor="#B5C 7DE"></FooterStyle>
<Columns>
<asp:BoundColum n DataField="stri ng_id"
ReadOnly="true" HeaderText="Str ing ID"></asp:BoundColumn >
<asp:BoundColum n DataField="stri ng" ReadOnly="true"
HeaderText="Str ing"></asp:BoundColumn >
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="Blac k"
BackColor="#999 999" Mode="NumericPa ges"></PagerStyle>
</asp:datagrid><a sp:dropdownlist id="Language_Dr opDownList"
style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 24px"
runat="server"
AutoPostBack="T rue"></asp:dropdownlis t><asp:label id="Label1"
style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 24px"
runat="server"
Width="248px" Font-Bold="True">Cho ose 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.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
using System.Xml.Xsl;
using System.Xml;

namespace PDM.excel
{
/// <summary>
/// Summary description for WebForm3.
/// </summary>
public class WebForm3 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
public SqlConnection conDB = new SqlConnection() ;

static public string[] LanguageStr =
{
"English","Fren ch","Spanish" };
static public string[] DropDownListStr =
{
"Language_DropD ownList"};
protected System.Web.UI.W ebControls.Drop DownList
Language_DropDo wnList;
protected System.Web.UI.W ebControls.Labe l Label1;
protected System.Web.UI.W ebControls.Butt on Button1;

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

private void Fill_DropDownLi st()
{
for (int i = 0; i < DropDownListStr .Length; i++)
{
string CtrlName= DropDownListStr[i];
DropDownList MyList =
(DropDownList)P age.FindControl (CtrlName);
// Populate all the checkboxes
string[] ToPopulate = AddStrArray[i];
for (int j = 0; j < ToPopulate.Leng th; j++)
{
MyList.Items.Ad d(new ListItem(ToPopu late[j],
j.ToString()));
}
}
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if(!Page.IsPost Back)
{
Fill_DropDownLi st();
}

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Language_D ropDownList.Sel ectedIndexChang ed += new
System.EventHan dler(this.Langu age_DropDownLis t_SelectedIndex Changed);
this.Button1.Cl ick += new
System.EventHan dler(this.Butto n1_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public DataSet DataToExcel = new DataSet();

public void BindGrid (int index)
{
conDB.Connectio nString = "data
source=10.195.1 7.7;database=de vnew;uid=bounaa jak;pwd=ehsfirs t;packet
size=4096";
SqlDataAdapter da = new SqlDataAdapter( "Select string_id,
string from pdm_translation s where language_id = 1 and string_id not in
(select string_id from pdm_translation s where language_id = " +
index.ToString( ) + ") ", conDB);
da.Fill(DataToE xcel, "DataToExce l");
Session["Tabla"] = Language_DropDo wnList.Selected Item.Text;
DataToExcel.Wri teXml(Server.Ma pPath(Session["Tabla"] +
".xml"));
DataGrid1.DataS ource = DataToExcel;
DataGrid1.DataB ind();
// Get row count
int nRowCount = DataToExcel.Tab les["DataToExce l"].Rows.Count;
// Store Row count in Session variable
Session["RowCount"] = nRowCount;
}
private void Language_DropDo wnList_Selected IndexChanged(ob ject
sender, System.EventArg s e)
{
int getSelectedInde x = Language_DropDo wnList.Selected Index+1;
BindGrid(getSel ectedIndex);

}

public void DataGridToExcel (DataGrid Export,HttpResp onse Response)
{

// Set the Response mime type for excel
Response.Conten tType = "applicatio n/vnd.ms-excel";
// Create a String Writer
System.IO.Strin gWriter stringWrite = new
System.IO.Strin gWriter();
Response.Charse t = "";
this.EnableView State = false;
System.IO.Strin gWriter tw = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter hw = new
System.Web.UI.H tmlTextWriter(t w);
DataGrid1.Rende rControl(hw);
Response.Write( tw.ToString());
Response.End();

}

private void Button1_Click(o bject sender, System.EventArg s 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 1856
http://www.experts-exchange.com/Prog..._21265758.html

:-)

"Luis Esteban Valencia" <lu*******@hace b.com> wrote in message news:e8******** ******@TK2MSFTN GP09.phx.gbl...
Here is my aspx code:
=============
<%@ Page language="c#" Codebehind="Web Form3.aspx.cs" AutoEventWireup ="false"
Inherits="PDM.e xcel.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="C#" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</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="Vert ical" AutoGenerateCol umns="False"
CellPadding="3" BackColor="Whit e" BorderWidth="1p x" BorderStyle="No ne"
BorderColor="#E 7E7FF">
<SelectedItemSt yle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#738 A9C"></SelectedItemSty le>
<AlternatingIte mStyle
BackColor="#F7F 7F7"></AlternatingItem Style>
<ItemStyle ForeColor="#4A3 C8C"
BackColor="#E7E 7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#4A3 C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3 C8C"
BackColor="#B5C 7DE"></FooterStyle>
<Columns>
<asp:BoundColum n DataField="stri ng_id"
ReadOnly="true" HeaderText="Str ing ID"></asp:BoundColumn >
<asp:BoundColum n DataField="stri ng" ReadOnly="true"
HeaderText="Str ing"></asp:BoundColumn >
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="Blac k"
BackColor="#999 999" Mode="NumericPa ges"></PagerStyle>
</asp:datagrid><a sp:dropdownlist id="Language_Dr opDownList"
style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 24px"
runat="server"
AutoPostBack="T rue"></asp:dropdownlis t><asp:label id="Label1"
style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 24px"
runat="server"
Width="248px" Font-Bold="True">Cho ose 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.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
using System.Xml.Xsl;
using System.Xml;

namespace PDM.excel
{
/// <summary>
/// Summary description for WebForm3.
/// </summary>
public class WebForm3 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
public SqlConnection conDB = new SqlConnection() ;

static public string[] LanguageStr =
{
"English","Fren ch","Spanish" };
static public string[] DropDownListStr =
{
"Language_DropD ownList"};
protected System.Web.UI.W ebControls.Drop DownList
Language_DropDo wnList;
protected System.Web.UI.W ebControls.Labe l Label1;
protected System.Web.UI.W ebControls.Butt on Button1;

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

private void Fill_DropDownLi st()
{
for (int i = 0; i < DropDownListStr .Length; i++)
{
string CtrlName= DropDownListStr[i];
DropDownList MyList =
(DropDownList)P age.FindControl (CtrlName);
// Populate all the checkboxes
string[] ToPopulate = AddStrArray[i];
for (int j = 0; j < ToPopulate.Leng th; j++)
{
MyList.Items.Ad d(new ListItem(ToPopu late[j],
j.ToString()));
}
}
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if(!Page.IsPost Back)
{
Fill_DropDownLi st();


}

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Language_D ropDownList.Sel ectedIndexChang ed += new
System.EventHan dler(this.Langu age_DropDownLis t_SelectedIndex Changed);
this.Button1.Cl ick += new
System.EventHan dler(this.Butto n1_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public DataSet DataToExcel = new DataSet();



public void BindGrid (int index)
{
conDB.Connectio nString = "data
source=10.195.1 7.7;database=de vnew;uid=bounaa jak;pwd=ehsfirs t;packet
size=4096";
SqlDataAdapter da = new SqlDataAdapter( "Select string_id,
string from pdm_translation s where language_id = 1 and string_id not in
(select string_id from pdm_translation s where language_id = " +
index.ToString( ) + ") ", conDB);
da.Fill(DataToE xcel, "DataToExce l");
Session["Tabla"] = Language_DropDo wnList.Selected Item.Text;
DataToExcel.Wri teXml(Server.Ma pPath(Session["Tabla"] +
".xml"));
DataGrid1.DataS ource = DataToExcel;
DataGrid1.DataB ind();
// Get row count
int nRowCount = DataToExcel.Tab les["DataToExce l"].Rows.Count;
// Store Row count in Session variable
Session["RowCount"] = nRowCount;


}
private void Language_DropDo wnList_Selected IndexChanged(ob ject
sender, System.EventArg s e)
{
int getSelectedInde x = Language_DropDo wnList.Selected Index+1;
BindGrid(getSel ectedIndex);

}

public void DataGridToExcel (DataGrid Export,HttpResp onse Response)
{

// Set the Response mime type for excel
Response.Conten tType = "applicatio n/vnd.ms-excel";
// Create a String Writer
System.IO.Strin gWriter stringWrite = new
System.IO.Strin gWriter();
Response.Charse t = "";
this.EnableView State = false;
System.IO.Strin gWriter tw = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter hw = new
System.Web.UI.H tmlTextWriter(t w);
DataGrid1.Rende rControl(hw);
Response.Write( tw.ToString());
Response.End();

}

private void Button1_Click(o bject sender, System.EventArg s 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
4176
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) meaning Language) has been brought in. This value can only have one of two values : N (for Nederlands - Dutch) and E (for English) If a language in the excel has not been put in, the prog displays a warning. After clicking the OK button of the...
0
5351
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 click the column headers all the columns sort except the hyperlink one. I checked the underlying dataview and that does get sorted so it seems like it is more of a display issue. I am guessing it has something to do with the hashtable used by the...
4
5401
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 displays with the template columns showing the Title and the Author from the first row in all rows. The other none template columns are fine. Obviously I am not understanding something here. What am I missing????? -- Barry Fitzgerald
0
1005
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 bound column, the other is a template column. The template column is built in the code-behind along with the databinding for the column. When the row is in edit mode the template column is a text box. All this, the building of the grid the...
1
1389
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 a choice to create one separate Excel file per Station ID.
4
1227
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). here is the code I use to present data in the datagrid: Code:
3
1578
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 help me on this problem.
1
1541
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 columns, otherwise it remains editable. I want to set this property in the itemdatabound event as the datagrid is loaded. Below is my ItemDataBound routine to show what I'm trying to do. Everything else works; I just need to be able to conditionally...
1
1117
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 dynamically as soon as the user opens the link of excel into the form. pls temme how to get the link into the form and how to retrieve the cells contents from that excel link and place into textboxes. pls gimme some guidance .. i jus know how to...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.