473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to export textbox in excel?

21 New Member
Hi,

How to export text box values in excel ? I need to export text box values in "excel".(when we click export to excel button)

Code:(when i click Export button i need to save text box value in excel sheet. ) In below code is working properly, But i need to save textbox value. (text box name is "txtBillable")


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  protected void btnExportToExcel_Click(object sender, EventArgs e)
  4.       {            
  5.  
  6.         gvHours.AllowPaging = false;
  7.         gvHours.AllowSorting = false;
  8.         gvHours.DataSource=Cache["dataset"];
  9.         gvHours.DataBind();
  10.         ChangeControlsToValue(gvHours);
  11.         Response.ClearContent();
  12.         string from = dtFrom.SelectedDate.ToShortDateString();
  13.         string to = dtTo.SelectedDate.ToShortDateString();
  14.         Response.AddHeader("content-disposition", "attachment; filename=" + from + "_to_" + to + ".xls");
  15.         Response.ContentType = "application/excel";
  16.         StringWriter sWriter = new StringWriter();
  17.         HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);
  18.         HtmlForm hForm = new HtmlForm();
  19.         gvHours.Parent.Controls.Add(hForm);
  20.         hForm.Attributes["runat"] = "server";
  21.         hForm.Controls.Add(gvHours);
  22.         hForm.RenderControl(hTextWriter);
  23.         Response.Write(sWriter.ToString());
  24.         gvHours.AllowPaging = true;
  25.         gvHours.AllowSorting = true;
  26.         gvHours.DataSource = Cache["dataset"];
  27.         gvHours.DataBind();      
  28.         Response.End();      
  29.  
  30.       }
  31.  
  32.       private void ChangeControlsToValue(Control gridView)
  33.       {
  34.         Literal literal = new Literal();
  35.  
  36.         for (int i = 0; i < gridView.Controls.Count; i++)
  37.         {
  38.           if (gridView.Controls[i].GetType() == typeof(LinkButton))
  39.           {
  40.             literal.Text = (gridView.Controls[i] as LinkButton).Text;
  41.             gridView.Controls.Remove(gridView.Controls[i]);
  42.             gridView.Controls.AddAt(i, literal);
  43.           }
  44.           else if (gridView.Controls[i].GetType() == typeof(DropDownList))
  45.           {
  46.             literal.Text = (gridView.Controls[i] as DropDownList).SelectedItem.Text;
  47.             gridView.Controls.Remove(gridView.Controls[i]);
  48.             gridView.Controls.AddAt(i, literal);
  49.           }
  50.           else if (gridView.Controls[i].GetType() == typeof(CheckBox))
  51.           {
  52.             literal.Text = (gridView.Controls[i] as CheckBox).Checked ? "True" : "False";
  53.             gridView.Controls.Remove(gridView.Controls[i]);
  54.             gridView.Controls.AddAt(i, literal);
  55.           }
  56.           if (gridView.Controls[i].HasControls())
  57.           {
  58.  
  59.             ChangeControlsToValue(gridView.Controls[i]);
  60.  
  61.           }
  62.  
  63.         }
  64.  
  65.       }
  66.  
  67.       protected void gvHours_RowDataBound(object sender, GridViewRowEventArgs e)
  68.       {
  69.         btnExportToExcel.Visible = true;
  70.       }
  71.  
  72.       protected void gvHours_SelectedIndexChanged(object sender, EventArgs e)
  73.       {
  74.  
  75.       }
  76.  
  77.     }
  78.  
  79.  
Please help me!(I need to save textbox value when we click export to excel button).
Jan 19 '12 #1
0 1639

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

Similar topics

3
by: Saur | last post by:
Hi, I am using an export to excel functionality from my ASP page. I have set the content type as Response.ContentType = "application/vnd.ms-excel" The data i am exporting has values like 1-2,...
0
by: Jason | last post by:
Can anyone point me to some sample code or tutorial that shows how I can export data from a database to an Excel spreadsheet that is already created on the server? I have an Excel spreadsheet...
6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
8
by: DC Gringo | last post by:
I have a simple button that should open another window and export a datagrid to an Excel file. I'm getting: "Name 'window' is not declared." What do I need to declare or import? <INPUT...
0
by: kieran | last post by:
Hi, I have an 'export to excel' button on my Datagrid. All works well except that on my Datagrid, I have sub total rows. The subtotal rows use colspan so that the subtotals are given above...
0
by: Sridhar | last post by:
Hi, I have a export to excel function where it exports the data of a datagrid into the excel sheet. For this, I am using the button and the text on that button reads "Export to Excel". Instead...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
1
by: JawzX01 | last post by:
Hello All, First, thank you for any help you can provide. I'm trying to do a simple export to excel. I've used the classic code that is all over the internet, and of course it worked without a...
0
by: mustaqueahmad | last post by:
Hi All, I am getting export to excel problem when I am giving IPAddress in URL, but it is working correct when am giving localhost and page name. eg : when I am writing My machine IP...
4
by: Tennotrumps | last post by:
I am trying to export a report to excel but the "excel" option is greyed out. I can export the query the report is based on, but not the report. However, if I open the database on another PC I...
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.