技术开发 频道

GridView 自定义查询翻页


【IT168技术文档】

  GridView 自定义查询翻页
  1.自定义LINKBUTTON
  2.dropdownlist翻页
  3.过滤引号及用 myAdapter.SelectCommand.Parameters.Add 方法过滤,防止SQL注入
  4.先显示所有值,后可查询关键字再翻页

  .ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MemberList.aspx.vb" Inherits="Manage_Members_MemberList" Debug="true"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>MemberList</title> <link rel="stylesheet" href="../Css/Moban_MM.css" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="90%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td style="height: 45px"><table style="border-collapse:collapse" width="100%" border="1" cellspacing="1" cellpadding="1" bordercolor="#CCCCCC"> <tr> <td bgcolor="#999999" height="21"><b><span Class =class="a180"><font color="#FFFFFF">会员列表 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:TextBox ID="keywords" runat="server" BackColor="NavajoWhite"></asp:TextBox> <asp:Button ID="btnSearch" runat="server" OnClick="searchGridView" Text="查询" /></font></span></b></td> </tr> </table> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="U_ID" ForeColor="Black" GridLines="None" Width="100%" OnRowDeleting="GridView1_OnRowDeleting" OnRowDataBound="GridView1_OnRowDataBound" PagerSettings-Visible="false" OnPageIndexChanging ="GridView1_OnPageIndexChanging" > <FooterStyle BackColor="Tan" /> <Columns> <asp:TemplateField HeaderText="编号"> <HeaderTemplate> <asp:Label ID="Label1" runat="server" Text="编号"></asp:Label><asp:CheckBox ID="chkAll" Visible="false" runat="server" ToolTip="全选" Text="编号" /> </HeaderTemplate> <ItemTemplate > <asp:CheckBox ID="chkItem" Visible="false" runat="server" /><%#Container.DataItemIndex + 1%> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="U_GameID" HeaderText="游戏ID" SortExpression="U_GameID" /> <asp:BoundField DataField="U_Name" HeaderText="用户名" SortExpression="U_Name" /> <asp:TemplateField HeaderText="性别" SortExpression="U_Sex"> <EditItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("U_Sex") %>' /> </EditItemTemplate> <ItemTemplate> <%#isSex(Eval("U_Sex"))%> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="U_EMail" HeaderText="Email" SortExpression="U_EMail" /> <asp:BoundField DataField="U_UserTruename" HeaderText="真实姓名" SortExpression="U_UserTruename" /> <asp:BoundField DataField="U_MsnQQ" HeaderText="Msn/QQ" SortExpression="U_MsnQQ" /> <asp:BoundField DataField="U_RegDatetime" HeaderText="注册时间" SortExpression="U_RegDatetime" /> <asp:CommandField DeleteText="&lt;span onclick=&quot;return confirm('确定删除吗?')&quot;&gt;删除&lt;/span&gt;" HeaderText="操作" ShowDeleteButton="True" ShowEditButton="True" /> </Columns> <PagerTemplate> </PagerTemplate> <RowStyle HorizontalAlign="Center" /> <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /> <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /> <HeaderStyle BackColor="Tan" Font-Bold="True" /> <AlternatingRowStyle BackColor="PaleGoldenrod" /> <PagerSettings Visible="False" /> </asp:GridView> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:Panel ID="PanelHyperLink" Visible="false" runat="server" Height="50px" Width="100%" HorizontalAlign="right" > 总共有 [<asp:Label ID="myRecordCount1" runat="server" Text="Label"></asp:Label>] 条记录; 页数 [<asp:Label ID="myPageIndex1" runat="server" Text="Label"></asp:Label>/<asp:Label ID="myPageCount1" runat="server" Text="Label"></asp:Label>] &nbsp;; <asp:HyperLink ID="PageFirst1" runat="server">首 页</asp:HyperLink> | <asp:HyperLink ID="PagePrevious1" runat="server">上一页</asp:HyperLink> | <asp:HyperLink ID="PageNext1" runat="server">下一页</asp:HyperLink> | <asp:HyperLink ID="PageLast1" runat="server">尾 页</asp:HyperLink> <asp:DropDownList AppendDataBoundItems="true" ID="myDDL1" runat="server"> <asp:ListItem Value="-1">跳转→</asp:ListItem> </asp:DropDownList> </asp:Panel> <asp:Panel ID="PanelLinkButton" runat="server" Height="50px" Width="100%" HorizontalAlign="right" > 总共有 [<asp:Label ID="myRecordCount" runat="server" Text="Label"></asp:Label>] 条记录; 页数 [<asp:Label ID="myPageIndex" runat="server" Text="Label"></asp:Label>/<asp:Label ID="myPageCount" runat="server" Text="Label"></asp:Label>] &nbsp;; <asp:LinkButton ID="PageFirst" CommandArgument="goPageFirst" OnClick="pageButtonClick" runat="server">首 页</asp:LinkButton> | <asp:LinkButton ID="PagePrevious" CommandArgument="goPagePrevious" OnClick="pageButtonClick" runat="server">上一页</asp:LinkButton> | <asp:LinkButton ID="PageNext" CommandArgument="goPageNext" OnClick="pageButtonClick" runat="server">下一页</asp:LinkButton> | <asp:LinkButton ID="PageLast" CommandArgument="goPageLast" OnClick="pageButtonClick" runat="server">尾 页</asp:LinkButton> <asp:DropDownList AppendDataBoundItems="true" ID="myDDL" runat="server" OnSelectedIndexChanged="myDDL_OnSelectedIndexChanged" AutoPostBack="true" > <asp:ListItem Value="-1">跳转→</asp:ListItem> </asp:DropDownList> </asp:Panel> </td> </tr> </table></td> </tr> </table> </div> </form> </body> </html>
0
相关文章