当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

ASP.NET GridView导出数据到Excel

  首先要把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?http://www.xvna.com" />

  <asp:CommandField HeaderText="删除" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/Admin/Images/del.gif?http://www.xvna.com" />

  </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>

相关内容
赞助商链接