[英]Changing Color of LinkButton in Repeater
I am creating a custom pagination for my GridView, so far I've done everything except this thing: I want to highlight the selected page in different color or different font style or anything I want to. 我正在为GridView创建一个自定义分页,到目前为止,我已经做完了所有事情,除了以下事情:我想用不同的颜色,不同的字体样式或任何我想要突出显示的页面。 For example if I have pages 1 2 3 4 5 6 and I do select 4, when it reloads the data from GridView I want 4 to be colored in Red 1 2 3 4 5 6. This is my aspx file
例如,如果我有页面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>
If u can give me any info about how can I put " | " away, so only the numbers be like LinkButtons, since now my LinkButton is NUMBER+" | " 如果您可以给我任何有关如何丢弃“ |”的信息,那么只有数字类似于LinkButtons,因为现在我的LinkButton是NUMBER +“ |”
My LinkButtonClick method 我的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);
}
and im filling the page like this 和即时通讯这样填满页面
pages.Add(new ListItem(i.ToString(),i.ToString(), i != (pageIndex + 1)));
Basicly I want to indicate which is the current page I am viewing atm. 基本上我想指出我正在查看atm的当前页面。
Thanks in advance. 提前致谢。
Set the ForeColor
property of the LinkButton
in the click handler, like this: 在单击处理程序中设置
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;
}
I solved it in a different way, using javascript : I added this function so a hidden label can take the value of the selected index, and then the selected index take the style of this label. 我使用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');
}
});
});
label: 标签:
<asp:Label ID="lblPageNum" style="display:none;" Class="lblPageNum" runat="server" />
and then simply change it in code-behind in the btnclick event 然后只需在btnclick事件的代码隐藏中对其进行更改
lblPageNum.Text = (pageIndex += 1).ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.