473,378 Members | 1,346 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,378 software developers and data experts.

good code to expot to excel sheet but need lil help

hi there,i am able to export the gridview data to excel sheet successfully but my gridview has 3 buttonfields like details etc etc which when clicked give the details,but i dont want those buttonfields to be in my excel sheet.plz help me.or alter the code below so that i can limit the columns to be exported to my excel sheet.



protected void BtnExport_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=Contacts.xls";

Response.ClearContent();

Response.AddHeader("content-disposition", attachment);

Response.ContentType = "application/ms-excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);
this.ClearControls(devViewGrid1);

devViewGrid1.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}
public override void VerifyRenderingInServerForm(Control control)
{
}


private void ClearControls(Control control)
{


for (int i = control.Controls.Count-1 ; i >= 0; i--)
{
ClearControls(control.Controls[i]);
}
if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);

try
{
literal.Text = (string)control.GetType().GetProperty("SelectedIte m").GetValue(control, null);
}
catch
{
}
control.Parent.Controls.Remove(control);
}
else
if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
literal.Text = (string)control.GetType().GetProperty("Text").GetV alue(control, null);
if (literal.Text != "Top n")

control.Parent.Controls.Add(literal);
control.Parent.Controls.Remove(control);
}

return;
}
}
Sep 11 '07 #1
1 1202
Hi hakeemkazmi]hi,

I will help you tomorrow. I have a solution for this one.

Best Regards,
Ruel


hi there,i am able to export the gridview data to excel sheet successfully but my gridview has 3 buttonfields like details etc etc which when clicked give the details,but i dont want those buttonfields to be in my excel sheet.plz help me.or alter the code below so that i can limit the columns to be exported to my excel sheet.



protected void BtnExport_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=Contacts.xls";

Response.ClearContent();

Response.AddHeader("content-disposition", attachment);

Response.ContentType = "application/ms-excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);
this.ClearControls(devViewGrid1);

devViewGrid1.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}
public override void VerifyRenderingInServerForm(Control control)
{
}


private void ClearControls(Control control)
{


for (int i = control.Controls.Count-1 ; i >= 0; i--)
{
ClearControls(control.Controls[i]);
}
if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);

try
{
literal.Text = (string)control.GetType().GetProperty("SelectedIte m").GetValue(control, null);
}
catch
{
}
control.Parent.Controls.Remove(control);
}
else
if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
literal.Text = (string)control.GetType().GetProperty("Text").GetV alue(control, null);
if (literal.Text != "Top n")

control.Parent.Controls.Add(literal);
control.Parent.Controls.Remove(control);
}

return;
}
}
Sep 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rajiv | last post by:
HI ALL, actually , i m working in a company having large number of employee , i have two userid and password . on id is from admin group(id given to me by technology manager) of the server and...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
13
by: Arno R | last post by:
Hi all, I will have to handle a lot of really 'nice' data in a LOT of Excel sheets. It is all about music files (Billboard top 100) I am afraid there really is a sheet for every year ... (Don't...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
10
by: cj | last post by:
I have a program I'm writing that has started executing the line following the line that is highlighted in the debugger. For instance for x = 1 to 3 messagebox.show(x) next when for x = 1...
4
by: e.h.doxtator | last post by:
All I'm a Python newbie, and I'm just getting to the wonders of COM programming. I am trying to programmatically do the following: 1. Activate Excel 2. Add a Workbook 3. Add a Worksheet...
7
by: Brave | last post by:
I am hoping for a code example of how to do this, and hopefully it will help me to see an easy way to code what seems to be a huge monster. I need to create a form that has two pulldown menues...
5
by: Rajesh | last post by:
Hi, Please help me to do an EXCEL report generation using ASP.NET. I am building an website. This should work in all machine. I need do load the data from SQL tables to excel sheet and user can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.