📄 paging-datagrid.aspx
字号:
<%@Page Language="C#"%>
<%@Import Namespace="System.Data" %>
<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>
<%@ Register TagPrefix="wrox" TagName="getdataview" Src="..\global\get-dataview-control.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Using Automatic Paging with a DataGrid Control</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
.rHead {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial;
font-size:14pt; font-weight:bold; padding:8px; color:green}
.rItem {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial,sans-serif;
font-size:10pt}
.rFoot {font-family:Tahoma,Arial; font-size:8pt; padding:8px; color:darkgray}
</style></head>
<body bgcolor="#ffffff">
<span class="heading">Using Automatic Paging with a DataGrid Control</span><hr />
<!--------------------------------------------------------------------------->
<%-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server" />
<%-- insert the control that creates the DataSet --%>
<wrox:getdataview id="ctlDataView" runat="server" />
<form runat="server">
'Previous' Link Text:
<ASP:TextBox id="PrevText" runat="server" />
'Next' Link Text:
<ASP:TextBox id="NextText" runat="server" /><br />
Paging Style:
<ASP:RadioButton id="PageNumeric" GroupName="Style"
runat="server" /> Numeric
<ASP:RadioButton id="PageText" GroupName="Style"
runat="server" /> Text<br />
Number of rows per Page:
<ASP:TextBox id="PageRows" runat="server" /><p />
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="90%"
AllowPaging="True"
PagerStyle-HorizontalAlign="Right"
OnPageIndexChanged="ChangeGridPage" />
</form>
<!--------------------------------------------------------------------------->
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// set the default values in the controls on the page
PrevText.Text = "Prev";
NextText.Text = "Next";
PageNumeric.Checked = true;
PageRows.Text = "10";
// set the initial page in the DataGrid to zero
// (not actually required as this is the default)
MyDataGrid.CurrentPageIndex = 0;
// create the data set and bind it to the DataGrid control
BindDataGrid();
}
}
void ChangeGridPage(Object objSender, DataGridPageChangedEventArgs objArgs )
{
// runs when one of the pager controls is clicked
// update the current page number from the parameter values
MyDataGrid.CurrentPageIndex = objArgs.NewPageIndex;
// recreate the data set and bind it to the DataGrid control
BindDataGrid();
}
void BindDataGrid()
{
// set the value of the number of rows per page
MyDataGrid.PageSize = Convert.ToInt32(PageRows.Text);
// set the type of pager to include in the DataGrid
if (PageNumeric.Checked == true)
MyDataGrid.PagerStyle.Mode = PagerMode.NumericPages;
else
MyDataGrid.PagerStyle.Mode = PagerMode.NextPrev;
// set the text for the pager to use when in NextPrev mode
MyDataGrid.PagerStyle.NextPageText = NextText.Text;
MyDataGrid.PagerStyle.PrevPageText = PrevText.Text;
// get connection string from ..\global\connect-strings.ascx user control
string strConnect = ctlConnectStrings.OLEDBConnectionString;
//create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList";
// create a variable to hold an instance of a DataView object
DataView objDataView;
// get DataView from get-dataview-control.ascx user control
objDataView = ctlDataView.GetDataView(strConnect, strSelect);
if (objDataView == null)
return;
// set the DataSource property of the DataList
MyDataGrid.DataSource = objDataView;
// and bind the control to the data
MyDataGrid.DataBind();
}
</script>
<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -