Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello Everybody,

I want to export 2 datagrid data in one excel sheet with company detail before record display.

plz i have stuck. help me out.

Thanking you.
Abdul
Posted
Updated 1-May-17 10:14am
Comments
DamithSL 5-Dec-14 22:24pm    
update the question with the code how you create and bind the grids and where you stuck? you know how to export single grid?
[no name] 1-May-17 9:11am    
Share your code what you have tried...

1 solution

try the following code

C#
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Label lbl1=new Label1();
GridView gv1 = new GridView();
GridView gv2 = new GridView();
string fileName="abc.xls";
Response.Clear();
Response.Charset = "utf-8";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");

Table table = new Table();
TableRow tr1 = new TableRow();
TableRow tr2 = new TableRow();
TableRow tr3 = new TableRow();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();

lbl1.Text="Company abc";

gv1.DataSource = data1;
gv1.DataBind();

gv2.DataSource = data2;
gv2.DataBind();

cell1.Controls.Add(lbl1);
tr1.Cells.Add(cell1);

cell2.Controls.Add(gv1);
tr2.Cells.Add(cell2);

cell3.Controls.Add(gv2);
tr3.Cells.Add(cell3);

table.RenderControl(htmlWrite);                
Response.Write(stringWrite.ToString());
Response.End();
htmlWrite.Dispose();
stringWrite.Dispose();
gv1.Dispose();
gv2.Dispose();
 
Share this answer
 
v4
Comments
Nirav Prabtani 2-May-17 7:56am    
Question is posted on 6-Dec-14 8:38am

Do you really think, This can be helpful today ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900