ASP.NET GridView导出数据到Excel(1)

作者:互联网   出处:控件中国网   2014-11-05 19:04:29   阅读:3

      本文介绍Windows环境下的java环境变量设置。

  首先要把GridView控件放到panel中


 <asp:Panel ID="Panel1" runat="server" Width="100%">
  <asp:GridView ID="gridview1" runat="server" Width="100%" CellPadding="4" ForeColor="#333333"
  AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" OnRowDeleting="gridview1_RowDeleting"
  OnRowEditing="gridview1_RowEditing" DataKeyNames="sno" OnDataBound="gridview1_DataBound"
  Font-Size="14px">
  <Columns>
  <asp:HyperLinkField DataTextField="sno" HeaderText="学号" DataNavigateUrlFields="sno"
  DataNavigateUrlFormatString="StudentInfo.aspx?id={0}" />
  <asp:BoundField DataField="sname" HeaderText="姓名" />
  <asp:BoundField DataField="ssex" HeaderText="性别" />
  <asp:BoundField DataField="snational" HeaderText="民族" />
  <%--<asp:BoundField DataField="sdegree" HeaderText="学历" />--%>
  <asp:BoundField DataField="spoliticalFace" HeaderText="整治面貌" />
  <asp:BoundField DataField="sphone" HeaderText="电话" />
  <asp:BoundField DataField="semail" HeaderText="E-mail" />
  <asp:BoundField DataField="saddress" HeaderText="住址" />
  <asp:BoundField DataField="sidcard" HeaderText="身份证号" />
  <asp:CommandField HeaderText="编辑" ShowEditButton="True" ButtonType="Image" EditImageUrl="~/Admin/Images/edit.gif" />
  <asp:CommandField HeaderText="删除" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/Admin/Images/del.gif" />
  </Columns>
  <PagerTemplate>//以下为自定义分页
  <div id="main">
  <table>
  <tr>
  <td style="text-align: left;">
  <div id="info">
  &nbsp;&nbsp;页次:<asp:Label ID="lblPageCurrent" runat="server" Text="1" CssClass="txtInfo"></asp:Label>
  /<asp:Label ID="lblPageCount" runat="server" Text="1"></asp:Label>&nbsp;&nbsp; 共&nbsp;<asp:Label
  ID="lblPageRow" runat="server" Text="1" CssClass="txtInfo"></asp:Label>&nbsp;条记录
  </div>
  </td>
  <td style="text-align: right;">
  <div id="page">
  <asp:LinkButton ID="btnFirst" runat="server" CssClass="link" CommandName="Pager"
  CommandArgument="First" OnCommand="NavigateToPage">[首页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnPrev" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Prev"
  OnCommand="NavigateToPage">[前一页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnNext" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Next"
  OnCommand="NavigateToPage">[下一页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnLast" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Last"
  OnCommand="NavigateToPage">[尾页]</asp:LinkButton>&nbsp;&nbsp;
  </div>
  </td>
  </tr>
  </table>
  </div>
  </PagerTemplate>

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat