GridView.BottomPagerRow 属性如在页导航中有个下拉列表选择页
获取一个 GridViewRow 对象,该对象表示 GridView 控件中的底部页导航行。
public virtual GridViewRow BottomPagerRow { get; }
属性值
一个 GridViewRow,表示控件中的底部页导航行。
备注 在启用分页时(通过将 AllowPaging 属性设置为 true),一个称为页导航行的附加行会自动显示在 GridView 控件中。页导航行包含用户可以用来导航至其他页的控件,并可以在控件的顶部、底部或同时在顶部和底部显示。使用 BottomPagerRow 属性以编程方式访问表示 GridView 控件中的底部页导航行的 GridViewRow 对象。
注意 |
|---|
|
BottomPagerRow 属性仅当 GridView 控件在 RowCreated 事件中创建了底部页导航行之后才可用。 |
此属性通常在需要以编程方式操作底部页导航行时(如添加自定义内容时)使用。对 BottomPagerRow 属性的任何修改必须在呈现 GridView 控件后执行;否则,GridView 控件将会改写所有更改。
示例 下面的代码示例演示如何使用 BottomPagerRow 属性访问 GridView 控件中的底部页导航行。BottomPagerRow 属性用来从页导航行中检索 DropDownList 控件。
<%@ Page language="C#" %>
<script runat="server">
void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
{
// Retrieve the pager row.
GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
// Retrieve the PageDropDownList DropDownList from the bottom pager row.
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
// Set the PageIndex property to display that page selected by the user.
CustomersGridView.PageIndex = pageList.SelectedIndex;
}
void CustomersGridView_DataBound(Object sender, EventArgs e)
{
// Retrieve the pager row.
GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
// Retrieve the DropDownList and Label controls from the row.
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
if(pageList != null)
{
// Create the values for the DropDownList control based on
// the total number of pages required to display the data
// source.
for(int i=0; i<CustomersGridView.PageCount; i++)
{
// Create a ListItem object to represent a page.
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
// If the ListItem object matches the currently selected
// page, flag the ListItem object as being selected. Because
// the DropDownList control is recreated each time the pager
// row gets created, this will persist the selected item in
// the DropDownList control.
if(i==CustomersGridView.PageIndex)
{
item.Selected = true;
}
// Add the ListItem object to the Items collection of the
// DropDownList.
pageList.Items.Add(item);
}
}
if(pageLabel != null)
{
// Calculate the current page number.
int currentPage = CustomersGridView.PageIndex + 1;
// Update the Label control with the current page information.
pageLabel.Text = "Page " + currentPage.ToString() +
" of " + CustomersGridView.PageCount.ToString();
}
}
</script>
<html>
<body>
<form runat="server">
<h3>GridView PagerTemplate Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
allowpaging="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<pagerstyle forecolor="Blue"
backcolor="LightBlue"/>
<pagertemplate>
<table width="100%">
<tr>
<td width="70%">
<asp:label id="MessageLabel"
forecolor="Blue"
text="Select a page:"
runat="server"/>
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
</td>
<td width="70%" align="right">
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
</td>
</tr>
</table>
</pagertemplate>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>

注意
浙公网安备 33010602011771号