There is a page number control on the ASP page.
<Pagertemplate> <Table width = "100%"> <tr class = "tdbg" align = "center"> <TD style = "height: 39px; text-align: center "class =" paginator "> total <% = This. pagecount %> page number of data entries: <asp: Label id = "labelcurrentpage" runat = "server" text = "<% # (gridview) container. namingcontainer ). pageindex + 1%> "> </ASP: Label>/<asp: Label id =" labelpagecount "runat =" server "text =" <% # (gridview) container. namingcontainer ). pagecount %> "> </ASP: Label> 15 entries per page <asp: linkbutton id = "linkbuttonfirstpage" runat = "server" commandargument = "first" commandname = "page" enabled = '<% # (gridview) container. namingcontainer ). pageindex! = 0%> '> homepage </ASP: linkbutton> <asp: linkbutton id = "linkbuttonpreviouspage" runat = "server" commandargument = "Prev" commandname = "page" enabled = '<% # (gridview) container. namingcontainer ). pageindex! = 0%> '> previous page </ASP: linkbutton> <asp: linkbutton id = "linkbuttonnextpage" runat = "server" commandargument = "Next" commandname = "page" enabled = '<% # (gridview) container. namingcontainer ). pageindex! = (Gridview) container. namingcontainer ). pagecount-1%> '> next page </ASP: linkbutton> <asp: linkbutton id = "linkbuttonlastpage" runat = "server" commandargument = "last" commandname = "page" enabled = '<% # (gridview) container. namingcontainer ). pageindex! = (Gridview) container. namingcontainer ). pagecount-1%> '> last page </ASP: linkbutton> to the <asp: textbox id = "txtnewpageindex" runat = "server" width = "20px" text = '<% # (gridview) container. parent. parent ). pageindex + 1%> '/> page <asp: linkbutton id = "btngo" runat = "server" causesvalidation = "false" commandargument = "-1" commandname = "page" text = "go"/> </TD> </ tr> </table> </pagertemplate>
Total number of data items: This. pagecount.
It is a variable in the background. C #
# Total number of region pages Public String pagecount {get {return viewstate ["pagecount"]. tostring () ;}set {viewstate ["pagecount"] = value ;}# total number of endregion pages
In the page load event of C #, assign the pagecount value to the initial value.
ViewState["pageCount"] = 0;
On the ASP page: An export button,
<Input type = "Submit" name = "searchpos0" value = "Export" id = "btnsearch0" class = "inputbutton" onmouseover = "this. classname = 'inputbutton _ hover '"runat =" server "onmouseout =" this. classname = 'inputcall' "onserverclick =" exportexcelstaff1click "onclick =" Return checkexport () "/>
JS script:
<SCRIPT>
Function checkexport (){
VaR n = <% = This. pagecount %>; ----------------------------- call the C # background variable.
If (n> 0 ){
Return true;
} Else {
Alert ("no data export ");
Return false;
}
}
</SCRIPT>
In this way, the prompt window is displayed. Click OK. The parent page is not refreshed.
Method 2:
In the C # code, determine the total number of data sources. When the number is 0, a window is displayed.
This. response. Write ("<script language = JavaScript> alert ('No data is exported! '); Window. Window. Location. href = 'bu36524analyse. aspx'; </SCRIPT> ");