gpt4 book ai didi

c# - 在 Repeater 中更改 LinkBut​​ton 的颜色

转载 作者:行者123 更新时间:2023-11-28 12:14:45 26 4
gpt4 key购买 nike

我正在为我的 GridView 创建一个自定义分页,到目前为止我已经完成了除了这件事之外的所有事情:我想用不同的颜色或不同的字体样式或我想要的任何东西突出显示所选页面。例如,如果我有页面 1 2 3 4 5 6 并且我确实选择了 4,当它从 GridView 重新加载数据时,我希望 4 被着色为红色 1 2 3 4 5 6。这是我的 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>

如果你能给我任何关于如何把“|”去掉的信息,那么只有数字像 LinkBut​​tons,因为现在我的 LinkBut​​ton 是 NUMBER+"| "

我的 LinkBut​​tonClick 方法

        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 的当前页面。

提前致谢。

最佳答案

在点击处理程序中设置 LinkBut​​tonForeColor 属性,如下所示:

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;
}

关于c# - 在 Repeater 中更改 LinkBut​​ton 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com