我想突出显示当前选择的页码。
ASP 代码:
<asp:Repeater ID="rptPaging" runat="server" onitemcommand="rptPaging_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%# Container.DataItem %>" runat="server" ><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
后端代码:
protected void rptPaging_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Page")
{
int index = e.Item.ItemIndex;
for (int i = 0; i < rptPaging.Items.Count; i++)
{
LinkButton btnlnk = rptPaging.Items[i].FindControl("btnPage") as LinkButton;
if (btnlnk != null)
{
btnlnk.CssClass = index == i ? "page_enabled" : string.Empty;
}
}
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
DisplayData();
}
}