Hopefully you guys can help me out. I tried a lot of different things and cant get this working.
I have a gridview as below in a update panel:
<asp:UpdatePanel ID="udpReport" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView runat="server" ID="preferenceReportGrd" AutoGenerateColumns="false"
AutoGenerateSelectButton="false" CaptionAlign="Top" EnableSortingAndPagingCallbacks="false" HorizontalAlign="left" CssSelectorClass="gvwPrefReport">
<Columns>
<asp:BoundField ReadOnly="true" DataField="ClientName" HeaderText="Company Name" />
<asp:BoundField ReadOnly="true" DataField="typeDescription" HeaderText="Preference" />
<asp:BoundField ReadOnly="true" DataField="defaultValue" HeaderText="Default Preference" />
<asp:BoundField ReadOnly="true" DataField="previousPreferenceValue" HeaderText="Previous Preference" />
<asp:BoundField ReadOnly="true" DataField="selectedValue" HeaderText="New Preference" />
<asp:BoundField ReadOnly="true" DataField="lastUpdated" HeaderText="Date Last Edited" />
</Columns>
</asp:GridView>
<div>
<user:MsgLine runat="server" ID="MsgLine1" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
I am trying to export this gridview out to excel. There is a button which the user clicks on it calls the on_click method for that button and in this on_click i have the following:
string attachment = "attachment; filename=Employee.xls";
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
preferenceReportGrd.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
I get nothing from this tried debugging it seems that when i mouse over stw.tostring() all the values for the gridview are there but nothing gets written out.