Asp.net: Highlight The Current (selected) Page Number in Repeater Pagination

In this tutorial I will explain how to get highlight the current (selected) page number in repeater pagination in Asp.net

Description:

In this tutorial I am using two repeater control (one to bind the data and 2nd one to display page number) and 4 link buttons (to go page First, Last, Next and Previous page). On page load only 4 page numbers will be visible when user clicks on page number 4 next page numbers will be display and so on. I am using PagedDatasource to do pagination in Repeater control.  When user clicks on any page number its must be highlighted e.g. change in color of selected page number.

Implementation:-
Write the below given code on ItemDataBound event of Repeater control which we are using for pagination.           
C#:-
    protected void repeaterpaging_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LinkButton lnk = (LinkButton)e.Item.FindControl("btnPage");
        if (lnk.CommandArgument.ToString() == (Pageno).ToString())
        {
            lnk.ForeColor = System.Drawing.Color.Black;
        }
        else
        {
            {
                lnk.ForeColor = System.Drawing.Color.White;
            }
        } 
    }

VB:-
Protected Sub repeaterpaging_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles repeaterpaging.ItemDataBound
        Dim lnk As LinkButton = DirectCast(e.Item.FindControl("btnPage"), LinkButton)
        If lnk.CommandArgument.ToString() = (Pageno).ToString() Then
            lnk.ForeColor = System.Drawing.Color.Black
        Else
            If True Then
                lnk.ForeColor = System.Drawing.Color.White
            End If
        End If
    End Sub 

Build, run the project and see the result. 

DEMO:
Asp.net: Highlight The Current (selected) Page Number in Repeater Pagination

 In this article we have learn how to highlight the current (selected) page number in repeater control pagination in Asp.net(C#,VB). I hope you enjoyed this article.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget