我将自定义分页写入转发器。下面是代码。当我单击链接按钮时,如何设置选中它或如何设置 css 类?
首先,我尝试像这样在 lbl_Click 函数中设置 css 类在lnk.CssClass = "classname";
每次尝试时,它都会将 css 类设置为所有单击的链接按钮。
private void CreatePagingControl()
{
for (int i = 0; i < pages; i++)
{
LinkButton lnk = new LinkButton();
lnk.Click += new EventHandler(lbl_Click);
lnk.ID = "lnkPage" + (i + 1).ToString();
lnk.Text = (i + 1).ToString();
plcPaging.Controls.Add(lnk);
Label spacer = new Label();
spacer.Text = " | ";
plcPaging.Controls.Add(spacer);
}
}
void lbl_Click(object sender, EventArgs e)
{
LinkButton lnk = sender as LinkButton;
int currentPage = int.Parse(lnk.Text);
int take = currentPage * 15;
int skip = currentPage == 1 ? 0 : take - 15;
FetchData(take, skip);
}
aspx
<asp:PlaceHolder ID="plcPaging" runat="server" />