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)



 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);           }           else if (gridView.Controls[i].GetType() == typeof(DropDownList))           {             literal.Text = (gridView.Controls[i] as DropDownList).SelectedItem.Text;             gridView.Controls.Remove(gridView.Controls[i]);             gridView.Controls.AddAt(i, literal);           }           else if (gridView.Controls[i].GetType() == typeof(CheckBox))           {             literal.Text = (gridView.Controls[i] as CheckBox).Checked ? "True" : "False";             gridView.Controls.Remove(gridView.Controls[i]);             gridView.Controls.AddAt(i, literal);           }           if (gridView.Controls[i].HasControls())           {              ChangeControlsToValue(gridView.Controls[i]);            }          }        }        protected void gvHours_RowDataBound(object sender, GridViewRowEventArgs e)       {         btnExportToExcel.Visible = true;       }        protected void gvHours_SelectedIndexChanged(object sender, EventArgs e)       {        }      }

(when i click Export button i need to save text box value in excel sheet. ) In above code is working properly to export to excel ,  But at the same time i need to save textbox value. (text box name is "txtBillable")


Please help me!