如何在 Gridview 分页器中将 NextPageText/NextPageUrl 从“...”更改为“Next”?

问题描述 投票:0回答:1
c# asp.net gridview pagination
1个回答
3
投票

我也遇到了同样的问题,我用这段代码解决了:

Protected Sub grdPatsCliente_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles grdPatsCliente.RowCreated
    If e.Row.RowType = DataControlRowType.Pager Then
        Dim i As Integer = 0
        For Each ctl As Control In e.Row.Cells(0).Controls(0).Controls(0).Controls
            i += 1
            If ctl.Controls(0).GetType.ToString = "System.Web.UI.WebControls.DataControlPagerLinkButton" Then
                Dim lnk As LinkButton = CType(ctl.Controls(0), LinkButton)
                If lnk.Text = "..." Then
                    If i < 3 Then
                        lnk.Text = "Prev"
                    Else
                        lnk.Text = "Next"
                    End If
                End If
            End If
            Dim x As String = ctl.ClientID
        Next
    End If
End Sub

默认的 Gridview 分页器始终在下一个和上一个链接上呈现“...”。使用此代码,我将“...”替换为我的文本(如果您使用FontsAwesome,也可以使用“”等 HTML)

C#代码:

protected void grdPatsCliente_RowCreated(object sender, GridViewRowEventArgs e) {
    if (e.Row.RowType == DataControlRowType.Pager) {
        int i = 0;
        foreach (Control ctl in e.Row.Cells[0].Controls[0].Controls[0].Controls) {
            i++;
            if (ctl.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlPagerLinkButton") {
                LinkButton lnk = (LinkButton)ctl.Controls[0];
                if (lnk.Text == "...") {
                    if (i < 3) {
                        lnk.Text = "Prev";
                    } else {
                        lnk.Text = "Next";
                    }
                }
            }
        }
    }
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.