源代码共享!DataGrid封装排序,分页,调用代码只需要一行!!!(原创)
注意:
1.自己修改一下数据库连接。
2.里面有个图片会找不到"images\go.gif"。自己找一个。
3.调用极其简单,把控件拖到页面上,只要写一行代码(自己取数据库的代码除外)。
4.有些其它属性自己看。
下面是代码:(自己创建ASP.NET工程)
PageGrid.ascx
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="PageGrid.ascx.vb" Inherits="GridDemo.PageGrid" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<font face="宋体">
<asp:panel id="Panel1" runat="server" height="443px" width="100%">
<asp:panel id="Panelabove" width="100%" height="6px" runat="server">
<asp:label id="labpg2" width="57px" height="5px" runat="server"></asp:label>
<asp:linkbutton id="FirstPage2" width="8px" height="11px" runat="server" font-names="Webdings" tooltip="第一页"
commandname="First">9</asp:linkbutton>
<asp:linkbutton id="PreviousPage2" width="10px" height="11px" runat="server" font-names="Webdings"
tooltip="前一页" commandname="Previous">7</asp:linkbutton>
<asp:linkbutton id="NextPage2" width="11px" height="10px" runat="server" font-names="Webdings" tooltip="后一页"
commandname="Next">8</asp:linkbutton>
<asp:linkbutton id="LastPage2" width="7px" height="12px" runat="server" font-names="Webdings" tooltip="最后页"
commandname="Last">:</asp:linkbutton>
<asp:textbox id="txtJump2" width="30px" height="17px" runat="server" font-names="宋体" tooltip="请输入页码"
font-size="Smaller"></asp:textbox>
<asp:imagebutton id="GoPage2" runat="server" tooltip="跳转" imageurl="images\GO.GIF"></asp:imagebutton>
</asp:panel>
<BR>
<asp:datagrid id="DataGrid1" width="100%" height="315px" runat="server" allowpaging="True" allowsorting="True">
<PagerStyle Visible="False" Position="TopAndBottom"></PagerStyle>
</asp:datagrid>
<BR>
<asp:panel id="Panelblow" width="100%" height="1px" runat="server">
<asp:label id="labpg" width="58px" runat="server"></asp:label>
<asp:linkbutton id="FirstPage" width="12px" height="8px" runat="server" font-names="Webdings" tooltip="第一页"
commandname="First">9</asp:linkbutton>
<asp:linkbutton id="PreviousPage" width="1px" height="10px" runat="server" font-names="Webdings"
tooltip="前一页" commandname="Previous">7</asp:linkbutton>
<asp:linkbutton id="NextPage" width="5px" height="17px" runat="server" font-names="Webdings" tooltip="后一页"
commandname="Next">8</asp:linkbutton>
<asp:linkbutton id="LastPage" width="7px" height="15px" runat="server" font-names="Webdings" tooltip="最后页"
commandname="Last">:</asp:linkbutton>
<asp:textbox id="txtJump" width="30px" height="17px" runat="server" font-names="宋体" tooltip="请输入页码"
font-size="Smaller"></asp:textbox>
<asp:imagebutton id="GoPage" runat="server" tooltip="跳转" imageurl="images\GO.GIF"></asp:imagebutton>
</asp:panel>
<BR>
</asp:panel>
</font>