引用第三方控件
引入AspNetPager.dll分页文件添加到bin目录下
在引用页中注册
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
在引用页中应用控件
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="center" OnPageChanged="AspNetPager1_PageChanged"
OnPageChanging="AspNetPager1_PageChanging" PageSize="15" Width="100%">
</webdiyer:AspNetPager>
查询控件如下:
<td style="height:100%; border: 1px solid #B5C3EF" valign="top" nowrap="">
<table>
<tr valign="top">
<td>查询条件:
<asp:DropDownList
ID="ddlQueryType" runat="server" Width="83px">
<asp:ListItem Value="StatutoryAgent" Selected="True">法人代表</asp:ListItem>
<asp:ListItem Value="RegistCapital">注册资本</asp:ListItem>
<asp:ListItem Value="SetupTime">注册时间</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DDLFilter" runat="server" Width="51px">
<asp:ListItem Value="like">包含</asp:ListItem>
<asp:ListItem Value=">">大于</asp:ListItem>
<asp:ListItem Value="<">小于</asp:ListItem>
<asp:ListItem Value="=">等于</asp:ListItem>
</asp:DropDownList>
</td>
<td><mc:DropDownCalendar ID="DDCSetupTime" runat="server" BorderStyle="Inset" BorderWidth="1px">
<WeekendDayStyle BackColor="#C0FFFF" ForeColor="Brown" />
<TitleStyle BackColor="#C00000" ForeColor="White" />
<DayHeaderStyle BackColor="#C0C0FF" />
<DateStyle BackColor="#FFFFC0" />
</mc:DropDownCalendar>
</td>
<td> <asp:TextBox ID="txtQueryValue" runat="server" CssClass="DownTextBox" Width="172px"></asp:TextBox></td>
<td><asp:Button ID="btnSearch" runat="server" CssClass="blueButtonCss" Text="查 询" Width="61px" OnClick="btnSearch_Click" /></td>
</tr>
</table>
</td>
托一gridview控件
代码如下:
<asp:GridView ID="GVShareHolder" SkinID="GridView8" Width="100%" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="SID" AutoGenerateColumns="False" OnRowDeleting="GVShareHolder_RowDeleting">
<Columns>
<asp:BoundField DataField="SID" HeaderText='<%$ Resources:Companys,SID %>' />
<asp:TemplateField HeaderText='<%$ Resources:Companys,gvshopCardID %>' >
<ItemTemplate>
<asp:HyperLink ID="HyperLinkCardID" runat="server" NavigateUrl='<%# "javascript:OpenWindow(\"/_layouts/GSEGC/Law/GetShopCard.aspx?o=View&sid="+Eval("SID").ToString()+"\");" %>' Text='<%# Bind("CardID") %>' onmouseover="TagToTip('T2TBalloon', BALLOON, true, FADEIN, 400, FADEOUT, 400, ABOVE,true, WIDTH, 260, PADDING, 8, TEXTALIGN, 'left', OFFSETX, -10)" />
<span id="T2TBalloon" style="display:none"><%= Resources.Companys.ShopRunScope %><b><%# Eval("RunScope") + "\n\t"%></b><br /><%=Resources.Companys.ShopPlace %><b><%# Eval("Place")%></b> </span>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RegistCapital" HeaderText='<%$ Resources:Companys,gvShopRegistCapital %>' />
<asp:TemplateField HeaderText='<%$ Resources:Companys,gvshopStatutoryAgent %>'>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("StatutoryAgent") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SetupTime" HeaderText='<%$ Resources:Companys,gvShopSetupTime %>' />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "javascript:OpenWindow(\"/_layouts/GSEGC/Law/GetShopCard.aspx?o=View&sid="+Eval("SID").ToString()+"\");" %>'>
<%=Resources.Companys.select %></asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# "javascript:OpenWindow(\"/_layouts/GSEGC/Law/GetShopCard.aspx?o=Edit&sid="+Eval("SID").ToString()+"\");" %>'>
<%=Resources.Companys.btnUpdate %></asp:HyperLink>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('确定要删除吗?');">
<%=Resources.Companys.btnDelete %></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
添加AspNetPager1_PageChanged代码:
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
try
{
if (this.txtQueryValue.Text == "")
{
AspNetPager1.RecordCount = ShopCardInfo.GetShopCardCount();
GVShareHolder.DataSource = ShopCardInfo.GetPagedLaw_ShopCard(this.AspNetPager1.StartRecordIndex, this.AspNetPager1.PageSize);
GVShareHolder.DataBind();
}
else
{
GetFilterData();
}
}
catch (Exception)
{
throw;
}
}
添加AspNetPager1_PageChanging代码:
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.LabShowPage.Visible = true;
LabShowPage.Text = (string)base.GetGlobalResourceObject("Companys", "cur") + " " + e.NewPageIndex;
}
定义查询函数GetFilterData()如下:
private void GetFilterData()
{
try
{
string filterStr = string.Empty;
int lastNum = this.AspNetPager1.StartRecordIndex + this.AspNetPager1.PageSize;
if (this.ddlQueryType.SelectedValue.Trim() == "RegistCapital")
{
filterStr = this.ddlQueryType.SelectedValue.Trim() + this.DDLFilter.SelectedValue.Trim() + "'" + float.Parse(this.txtQueryValue.Text.ToString()) + "'";
}
else if (this.ddlQueryType.SelectedValue.Trim() == "StatutoryAgent")
{
filterStr = this.ddlQueryType.SelectedValue.Trim() + this.DDLFilter.SelectedValue.Trim() + "'" + this.txtQueryValue.Text.ToString() + "'";
}
else if (this.ddlQueryType.SelectedValue.Trim() == "SetupTime")
{
this.txtQueryValue.Enabled = false;
filterStr = this.ddlQueryType.SelectedValue.Trim() + this.DDLFilter.SelectedValue.Trim() + "'" + this.DDCSetupTime.Value.ToString() + "'";
this.txtQueryValue.Enabled = true;
}
DataTable dt = ShopCardInfo.GetPageSizeVisited(filterStr);
DataView dv = dt.DefaultView;
dv.RowFilter = "RowNumber >= " + this.AspNetPager1.StartRecordIndex.ToString() + " and RowNumber <= " + lastNum.ToString();
this.AspNetPager1.RecordCount = dt.Rows.Count;
this.GVShareHolder.DataSource = dv;
this.GVShareHolder.DataBind();
}
catch (Exception)
{
throw;
}
}
查询按钮事件如下:
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
if (this.txtQueryValue.Text.ToString() == "" && this.ddlQueryType.SelectedValue.Trim() != "SetupTime")
{
AspNetPager1.RecordCount = ShopCardInfo.GetShopCardCount();
GVShareHolder.DataSource = ShopCardInfo.GetPagedLaw_ShopCard(this.AspNetPager1.StartRecordIndex, this.AspNetPager1.PageSize);
GVShareHolder.DataBind();
}
else
{
GetFilterData();
}
}
catch (Exception)
{
throw;
}
}
分页存储过程
ALTER PROCEDURE [dbo].PageLaw_ShopCard
(
@startIndex INT,
@pageSize INT
)
AS
declare @Tab nvarchar(50)
declare @sql varchar(200)
set @sql = 'WITH tablelist AS (SELECT ROW_NUMBER() OVER (ORDER BY Tmp.SID DESC) AS Row, * from Law_ShopCard as Tmp)
SELECT * FROM tablelist WHERE Row between '+cast(@startIndex as varchar(20)) +' and '+ cast(@startIndex + @pageSize -1 as varchar(20))
begin
exec (@sql)
print @sql
end