Chriz L

Chriz L

  • NA
  • 220
  • 50.6k

Export to excel selected records from gridView

Sep 20 2017 5:30 AM
Hello,
 
I have a new functionality that I have to add to my ASP.NET solution and I could use some help. 
What I need to do is to select some records from a gridview  (based on select checkbox) and export those records to an excel file.
Here's my gridView:
  1.      <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" ShowFooter="true"  
  2.       OnPageIndexChanging="gv_PageIndexChanging" AllowPaging="True" PageSize="20">  
  3.     <Columns>  
  4.         <asp:TemplateField HeaderText="S/N" ItemStyle-Width="25">  
  5.             <ItemTemplate>  
  6.                 <asp:Label ID="lblrownum" runat="server"  Text='<%#Eval("rownum") %>' Width="25"></asp:Label>  
  7.             </ItemTemplate>  
  8.         </asp:TemplateField>  
  9.         <asp:TemplateField HeaderText="Appno">                
  10.             <ItemTemplate>  
  11.                 <asp:Label ID="lblAppNo" runat="server" Text='<%#Eval("Appno") %>' Width="40"></asp:Label>  
  12.             </ItemTemplate>  
  13.         </asp:TemplateField>                        
  14.         <asp:TemplateField HeaderText="IDNO">                
  15.             <ItemTemplate>  
  16.                 <asp:Label ID="lblIDNO" runat="server" Text='<%#Eval("IDNO") %>' Width="40"></asp:Label>  
  17.             </ItemTemplate>  
  18.         </asp:TemplateField>  
  19.         <asp:TemplateField HeaderText="Select" >                
  20.             <ItemTemplate>  
  21.                 <asp:CheckBox ID="cbSelected" runat="server" />  
  22.             </ItemTemplate>  
  23.         </asp:TemplateField>                            
  24.     </Columns>  
  25.       <PagerStyle HorizontalAlign="Left" VerticalAlign="Middle"/>  
  26. </asp:GridView>  
  27.   
  28. <asp:Button ID="btnExport" runat="server" Text="Export to Excel" />  
Any kind of help would be appreciated.
 
Thank you in advnce. 

Answers (2)