asp.net 自定义分页控件

这个分页的主要是用了四个linkbutton按纽的事件,然后利用后台传递的条件调用分页处理的方法,在这个控件中可以点击表头排序,并且可以突出显示关键字等。

显示的页面:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DataShow.ascx.cs" Inherits="DataShow" EnableViewState="false" %>

  
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 466px;">
                      
<tr>
                          
<td style="vertical-align: top; width: 100%; height: 233px; text-align: center;">
                           
<asp:GridView ID="GridViewFileList" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns
="False" CellPadding="4" GridLines="None" PageSize="20" Width="98%" OnRowDataBound="GridViewFileList_RowDataBound" OnSorting="GridViewFileList_Sorting">
          
            
<Columns>
                
<asp:BoundField DataField="FileID" Visible="False">
                    
<ItemStyle Height="26px" />
                    
<HeaderStyle Height="26px" />
                
</asp:BoundField>
                
<asp:TemplateField HeaderText="文件名" SortExpression="title">
                    
<HeaderStyle CssClass="gridheadshowdata" />
                    
<ItemTemplate>
                        
<asp:HyperLink ID="FileName" runat="server" Target="_blank" NavigateUrl='<%# "FileDetail.aspx?FileID="+Eval("FileID")%>' CssClass="griditemshowdata"
                            Text
='<%# Eval("title") %>' ToolTip='<%# Eval("FileDesc") %>'></asp:HyperLink>
                    
</ItemTemplate>
                    
<ItemStyle HorizontalAlign="Left" />
                
</asp:TemplateField>
                
<asp:BoundField DataField="FileTypeName" HeaderText="类别" SortExpression="FileTypeID" HtmlEncode="False">
                    
<ItemStyle Height="26px"   CssClass="griditemshowdata"  HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  Height="26px" />
                
</asp:BoundField>
                
<asp:BoundField DataField="GradeName" HeaderText="年级" SortExpression="GradeID" HtmlEncode="False">
                    
<ItemStyle CssClass="griditemshowdata" HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  />
                
</asp:BoundField>
                
<asp:BoundField DataField="FileSize" HeaderText="文件大小" SortExpression="FileSize2" HtmlEncode="False">
                    
<ItemStyle CssClass="griditemshowdata" HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  />
                
</asp:BoundField>
                
<asp:BoundField DataField="AddDate" DataFormatString="{0:d}" HeaderText="发布时间&lt;font color='#FF0000'&gt;↓&lt;/font&gt;" HtmlEncode="False"
                    SortExpression
="AddDate">
                    
<ItemStyle CssClass="griditemshowdata" Height="26px" HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  Height="26px" />
                
</asp:BoundField>
                
<asp:BoundField DataField="hit" HeaderText="下载次数" SortExpression="hit" HtmlEncode="False">
                    
<ItemStyle CssClass="griditemshowdata" Height="26px" HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  Height="26px" />
                
</asp:BoundField>
                
<asp:TemplateField>
                    
<HeaderTemplate>
                        下载
                    
</HeaderTemplate>
                    
<ItemStyle CssClass="griditemshowdata" Height="26px" HorizontalAlign="Center" />
                    
<HeaderStyle  CssClass="gridheadshowdata"  Height="26px" />
                    
<ItemTemplate>
                        
<a  href="GetDownloadFile.aspx?FileID=<%#Eval("FileID") %>&AddDate=<%#Eval("AddDate") %>&UpFile=<%#Eval("UpFile") %>">
                    
<%--    <a  href='<%#Eval("DownloadPath") %>'>--%>
                            
<asp:Image ID="Image2" runat="server" ImageUrl="~/images/icon_down.gif" /></a>
                    
</ItemTemplate>
                
</asp:TemplateField>
            
</Columns>
            
<RowStyle BackColor="#EFEFEF" />
            
<EmptyDataTemplate>
               
<table  border='0' cellpadding='0' cellspacing='0' style='border-right: coral 1px dotted;border-top: coral 1px dotted; border-left: coral 1px dotted; border-bottom: coral 1px dotted;background-color: #ffffff;width:100%;height:55px;'><tr><td align='center'><font color='coral'><b>对不起,没有搜索到相关的记录,我们将尽快上传相关数据<b></font></td></tr></table>
            
</EmptyDataTemplate>          
            
<HeaderStyle BackColor="#D5E4F4" Font-Bold="True" />
            
<AlternatingRowStyle BackColor="White" />           
        
</asp:GridView>    
                              
<asp:Panel ID="PanelPageTable" runat="server" Height="28px" Visible="False" Width="98%">
         
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 21px">
                                
<tr>
                                    
<td style="width: 100px; height: 13px">
                                        
</td>
                                    
<td style="width: 98px; height: 13px">
                                        
<div style="width: 212px; height: 7px; font-size:14px;">
                                                        总共
<%=RecordCount%>条 第                                                  
                                                        
<%=PageIndex%>/<%=PageCount %>
                                                        页
                                             
                                        
</div>
                                    
</td>
                                    
<td style="width: 97px; height: 13px">
                                        
<div style="width: 308px; height: 8px; text-align: right; font-size:14px;">
                                            
<asp:LinkButton ID="FirstPage" runat="server" CommandArgument="First" OnClick="FirstPage_Click"  >第一页</asp:LinkButton>
                                            
<asp:LinkButton ID="PreviousPage" runat="server" CommandArgument="Prev" OnClick="PreviousPage_Click" >上一页</asp:LinkButton>
                                            
<asp:LinkButton ID="NextPage" runat="server" CommandArgument="Next" OnClick="NextPage_Click"  >下一页</asp:LinkButton>
                                            
<asp:LinkButton ID="LastPage" runat="server" CommandArgument="Last" OnClick="LastPage_Click"  >最后一页</asp:LinkButton>
                                            
<asp:TextBox ID="TextGotoPage" runat="server" Font-Size="16px" CssClass="pageeditbox" Width="22px" Height="20px"></asp:TextBox>
                                            
<asp:Button ID="PageGo" Font-Size="16px" causesvalidation="False" commandargument="-1" commandname="Page" runat="server" CssClass="pagebutton" Text="Go" OnClick="PageGo_Click" Height="23px" Width="28px" />
                                        
</div>
                                    
</td>
                                    
<td style="width: 80px; height: 13px">
                                        
<div style="width: 4px; height: 1px">
                                        
</div>
                                    
</td>
                                
</tr>
                            
</table>   
                              
</asp:Panel>
    
<asp:HiddenField ID="HiddenFieldWhereCondition" runat="server" />
    
<asp:HiddenField ID="HiddenFieldPageIndex" runat="server" />
    
<asp:HiddenField ID="HiddenFieldPageCount" runat="server" />
    
<asp:HiddenField ID="HiddenFieldRecordCount" runat="server" />
    
<asp:HiddenField ID="HiddenFieldGridViewSortExpression" runat="server" />
    
<asp:HiddenField ID="HiddenFieldGridViewSortDirection" runat="server" />
                              
<asp:HiddenField ID="HiddenKeyWord" runat="server" />
        
                          
</td></tr>
                          
</table>

后台的CS代码:

 

Code

调用的函数:

 public DataTable SelectPageFiles(string WhereCondition, int PageIndex, int PageCount, string OrderCondition)

分页存储过程的参数:

--根据条件显示相应的记录,并分页。
ALTER PROC SelectPageFiles
@WhereCondition nvarchar(500),  --查询条件
@PageIndex int,        --页号
@PageCount int,        --每页的记录数
@OrderCondition varchar(50) --排序条件
as.
....

调用控件声明:

<%@ register tagprefix="MyTag" tagname="MyDataList" src="~/DataShow.ascx" %>

定义控件:

 <MyTag:MyDataList id="MyDataList1" runat="server"></MyTag:MyDataList>      

调用分页控件:

this.MyDataList1.BindDataSource(WhereCondition, this.keyword.Text.Trim());

 

posted on 2008-09-12 13:06  ringwang  阅读(635)  评论(0编辑  收藏  举报