.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to call textbox when export to excel?

Posted By: Murali     Posted Date: January 20, 2012    Points:5   Category :ASP.Net
Hi,

I am calling text box in grid view to export to excel, that text box in outside of grid , i need to save text box value when export to excel.

Below is my code for export to excel :(it's working)but i need to save textbox values in export to ecxel.

protected void btnExportToExcel_Click(object sender, EventArgs e)
{

gvHours.AllowPaging = false;
gvHours.AllowSorting = false;
gvHours.DataSource=Cache["dataset"];
gvHours.DataBind();
ChangeControlsToValue(gvHours);
Response.ClearContent();
string from = dtFrom.SelectedDate.ToShortDateString();
string to = dtTo.SelectedDate.ToShortDateString();
Response.AddHeader("content-disposition", "attachment; filename=" + from + "_to_" + to + ".xls");
Response.ContentType = "application/excel";
StringWriter sWriter = new StringWriter();
HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);
HtmlForm hForm = new HtmlForm();
gvHours.Parent.Controls.Add(hForm);
hForm.Attributes["runat"] = "server";
hForm.Controls.Add(gvHours);
hForm.RenderControl(hTextWriter);
Response.Write(sWriter.ToString());
gvHours.AllowPaging = true;
gvHours.AllowSorting = true;
gvHours.DataSource = Cache["dataset"];
gvHours.DataBind();
Response.End();

}
private void ChangeControlsToValue(Control gridView)
{
Literal literal = new Literal();

for (int i = 0; i < gridView.Controls.Count; i++)
{
if (gridView.Controls[i].GetType() == typeof(LinkButton))
{
literal.Text = (gridView.Controls[i] as LinkButton).Text;
gridView.Controls.Remove(gridView.Controls[i]);
gridView.Controls.AddAt(i, literal);
}
if (gridView.Controls[i].HasControls())
{

ChangeControlsToValue(gridView.Controls[i]);

}

}

}

Responses
Author: Deco             
Posted Date: January 20, 2012     Points: 20   

You are adding only the GridView to the html form
please add the textbox also.
You have to place the TextBox control inside the gridview or you can place a div tag which covers the textBox as well as the gridview and can render the div tag to get the textbox content exported to Excel

Regards,
Deco
Author: Murali             
Posted Date: January 20, 2012     Points: 20   

Hi Alwyn Duraisingh,

when i was insert text box in grid view, how can i declare text box ?
how to give div tag?
it is not possible to save outside of text box in when export to excel in grid view?

please help me!



Author: Murali             
Posted Date: January 20, 2012     Points: 20   

Hi Alwyn Duraisingh,

when i was inser text box in grid view, how can i declare text box ?

it is not possible to save outside of text box in when export to excel in grid view?




Author: jason663             
Posted Date: July 23, 2013     Points: 20   

asp.net excel

This excel library works well:

https://www.kellermansoftware.com/p-52-excel-reports.aspx



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend