[英]Changing Color of LinkButton in Repeater
我正在为GridView创建一个自定义分页,到目前为止,我已经做完了所有事情,除了以下事情:我想用不同的颜色,不同的字体样式或任何我想要突出显示的页面。 例如,如果我有页面1 2 3 4 5 6,并且我确实选择4,那么当它从GridView重新加载数据时,我希望4变成红色1 2 3 4 56。这是我的aspx文件
<asp:Repeater ID="repeaterPaging" runat="server" >
<ItemTemplate>
<asp:LinkButton ID="pagingLinkButton" runat="server"
Text='<%#Eval("Text") +" | " %>'
CommandArgument='<%# Eval("Value") %>'
Enabled='<%# Eval("Enabled")%>'
OnClick="linkButton_Click" ForeColor="White" Font-Bold="True" Font-Underline="false">
</asp:LinkButton>
</ItemTemplate>
如果您可以给我任何有关如何丢弃“ |”的信息,那么只有数字类似于LinkButtons,因为现在我的LinkButton是NUMBER +“ |”
我的LinkButtonClick方法
protected void linkButton_Click(object sender, EventArgs e)
{
//int totalRows = 0;
LinkButton lb = (LinkButton)sender;
lb.Attributes.Add("class", "BlackLnkBtn");
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
pageIndex -= 1;
gridViewSearchReport.PageIndex = pageIndex;
//gridViewSearchReport.DataSource = EmployeeDataAccessLayer.
// GetEmployees(pageIndex, GridView1.PageSize, out totalRows);
// FetchData(pageIndex);
gridViewSearchReport.DataSource = FetchData(pageIndex+1);
gridViewSearchReport.DataBind();
DatabindRepeater(pageIndex, gridViewSearchReport.PageSize, RowNumber());
CheckButtonsAvailability(pageIndex + 1);
}
和即时通讯这样填满页面
pages.Add(new ListItem(i.ToString(),i.ToString(), i != (pageIndex + 1)));
基本上我想指出我正在查看atm的当前页面。
提前致谢。
在单击处理程序中设置LinkButton
的ForeColor
属性,如下所示:
protected void linkButton_Click(object sender, EventArgs e)
{
//int totalRows = 0;
LinkButton lb = (LinkButton)sender;
lb.Attributes.Add("class", "BlackLnkBtn");
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
pageIndex -= 1;
gridViewSearchReport.PageIndex = pageIndex;
//gridViewSearchReport.DataSource = EmployeeDataAccessLayer.
// GetEmployees(pageIndex, GridView1.PageSize, out totalRows);
// FetchData(pageIndex);
gridViewSearchReport.DataSource = FetchData(pageIndex+1);
gridViewSearchReport.DataBind();
DatabindRepeater(pageIndex, gridViewSearchReport.PageSize, RowNumber());
CheckButtonsAvailability(pageIndex + 1);
// Make the clicked link button red
lb.ForeColor = System.Drawing.Color.Red;
}
我使用javascript以另一种方式解决了该问题:我添加了此函数,以便隐藏标签可以采用所选索引的值,然后所选索引采用此标签的样式。
$().ready(function () {
$('#ctl00_ContentPlaceHolder1_lbPageView(THIS IS DIV ID OF THE ROW WHERE PAGINATION IS GENERATING>a').each(function () {
if ($(this).text() == $('.lblPageNum').text())
{
$(this).css('color', '#FDBE0E');
}
});
});
标签:
<asp:Label ID="lblPageNum" style="display:none;" Class="lblPageNum" runat="server" />
然后只需在btnclick事件的代码隐藏中对其进行更改
lblPageNum.Text = (pageIndex += 1).ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.