Pagination and query

Source: Internet
Author: User

ReferenceThird-party controls
Add the aspnetpager. dll paging file to the bin directory.

Register on the reference page
<% @ Register Assembly = "aspnetpager" namespace = "Wuqi. webdiyer" tagprefix = "webdiyer" %>

Apply controls on the reference page
<Webdiyer: aspnetpager id = "aspnetpager1" runat = "server" horizontalalign = "center" onpagechanged = "aspnetpager1_pagechanged"
Onpagechanging = "aspnetpager1_pagechanging" pagesize = "15" width = "100%">
</Webdiyer: aspnetpager>

Query controls As follows:
<TD style = "height: 100%; Border: 1px solid # b5c3ef" valign = "TOP" nowrap = "">
<Table>
<Tr valign = "TOP">
<TD> query condition:
<Asp: dropdownlist
Id = "ddlquerytype" runat = "server" width = "83px">
<Asp: listitem value = "statutoryagent" selected = "true"> legal representative </ASP: listitem>
<Asp: listitem value = "registcapital"> Registered Capital </ASP: listitem>
<Asp: listitem value = "setuptime"> registration time </ASP: listitem>
</ASP: dropdownlist>
<Asp: dropdownlist id = "ddlfilter" runat = "server" width = "51px">
<Asp: listitem value = "like"> include </ASP: listitem>
<Asp: listitem value = "& gt;"> greater than </ASP: listitem>
<Asp: listitem value = "& lt;"> less than </ASP: listitem>
<Asp: listitem value = "="> equal to </ASP: listitem>
</ASP: dropdownlist> & nbsp;
</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> & nbsp; <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>

Hold a gridview Control
Code As follows:
<Asp: gridview id = "gv1_holder" skinid = "gridview8" width = "100%" runat = "server" cellpadding = "4" forecolor = "#333333" gridlines = "NONE" datakeynames =" sid "autogeneratecolumns =" false "onrowdeleting =" gv1_holder_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>
& Nbsp; <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>
& Nbsp; <asp: linkbutton id = "linkbutton1" runat = "server" causesvalidation = "false" commandname = "delete" onclientclick = "Return confirm ('Are you sure you want to delete it? '); ">
<% = 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" type = "regxph" text = "yourobjectname"/>
<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>

Add the aspnetpager1_pagechanged code :
Protected void aspnetpager1_pagechanged (Object SRC, eventargs E)
{
Try
{
If (this.txt queryvalue. Text = "")
{
Aspnetpager1.recordcount = shopcardinfo. getshopcardcount ();
Gvdomainholder. datasource = shopcardinfo. getpagedlaw_shopcard (this. aspnetpager1.startrecordindex, this. aspnetpager1.pagesize );
Gv1_holder. databind ();
}
Else
{
Getfilterdata ();
}
}
Catch (exception)
{

Throw;
}
}

Add the aspnetpager1_pagechanging code:
Protected void aspnetpager1_pagechanging (Object SRC, Wuqi. webdiyer. pagechangingeventargs E)
{
This. labshowpage. Visible = true;
Labshowpage. Text = (string) base. getglobalresourceobject ("companys", "cur") + "& nbsp;" + E. newpageindex;
}

Define the query function getfilterdata () As follows:
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.txt queryvalue. Text. tostring () + "'";
}
Else if (this. ddlquerytype. selectedvalue. Trim () = "statutoryagent ")
{
Filterstr = This. ddlquerytype. selectedvalue. Trim () + this. ddlfilter. selectedvalue. Trim () + "'" + this.txt queryvalue. Text. tostring () + "'";
}
Else if (this. ddlquerytype. selectedvalue. Trim () = "setuptime ")
{
This.txt queryvalue. Enabled = false;
Filterstr = This. ddlquerytype. selectedvalue. Trim () + this. ddlfilter. selectedvalue. Trim () + "'" + this. ddcsetuptime. value. tostring () + "'";
This.txt queryvalue. 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. gv1_holder. datasource = DV;
This. gv1_holder. databind ();
}
Catch (exception)
{

Throw;
}
}

Query button events As follows:
Protected void btnsearch_click (Object sender, eventargs E)
{
Try
{
If (this.txt queryvalue. Text. tostring () = "" & this. ddlquerytype. selectedvalue. Trim ()! = "Setuptime ")
{
Aspnetpager1.recordcount = shopcardinfo. getshopcardcount ();
Gvdomainholder. datasource = shopcardinfo. getpagedlaw_shopcard (this. aspnetpager1.startrecordindex, this. aspnetpager1.pagesize );
Gv1_holder. databind ();
}
Else
{
Getfilterdata ();
}
}
Catch (exception)
{

Throw;
}
}

Paging Stored Procedure

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

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.