GridView的自定义分页
Protected
Sub EmployeeGridView_Selected()
Sub EmployeeGridView_Selected( ByVal sender As Object , ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected If TypeOf e.ReturnValue Is DataTable Then ' _totalCount = DirectCast(e.ReturnValue, DataTable).Rows.Count ElseIf TypeOf e.ReturnValue Is Integer Then ' _totalCount = DirectCast (e.ReturnValue, Integer ) End If End Sub
'
在 EmployeeGridView_RowDataBound 的事件中 下如下代码:
Const
_pagerFormat
As
String
=
"
{0}/{1}ページ({2}-{3}件目)/全{4}件
"
If
e.Row.RowType
=
DataControlRowType.Pager
Then
totalCount
=
DirectCast
(ViewState(VIEWSTATE_TOTALCOUNT),
Integer
)
Dim
pageInfo
As
Literal
=
New
Literal()
Dim
startIndex
As
Integer
=
SyohsaiList.PageIndex
*
SyohsaiList.PageSize
+
1
Dim
endIndex
As
Integer
=
DirectCast
(
IIf
(startIndex
+
SyohsaiList.PageSize
>
totalCount, totalCount, _ startIndex
+
SyohsaiList.PageSize
-
1
),
Integer
) pageInfo.Text
=
String
.Format(System.Globalization.CultureInfo.InvariantCulture, PAGER_FORMAT, SyohsaiList.PageIndex
+
1
, SyohsaiList.PageCount, _ startIndex, endIndex, totalCount)
Dim
tc
As
TableCell
=
New
TableCell() tc.Controls.Add(pageInfo) e.Row.Cells(
0
).Controls(
0
).Controls(
0
).Controls.AddAt(
0
, tc)
End
If
If
e.Row.RowType
=
DataControlRowType.Pager
Then
e.Row.CssClass
=
CSS_PAGER
End
If
注释少,因为原来做的都是对日的,我把日文注释都删掉了。 大家有需要的可以联系我,和我要。