在Repeater中改变LinkButton的颜色(Changing Color of LinkButton in Repeater)

编程入门 行业动态 更新时间:2024-10-15 20:16:16
在Repeater中改变LinkButton的颜色(Changing Color of LinkButton in Repeater)

我正在为我的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)));

基本上我想说明哪个是我正在查看的当前页面。

提前致谢。

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. 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

<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+" | "

My LinkButtonClick method

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.

Thanks in advance.

最满意答案

在Click处理程序中设置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.

$().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

lblPageNum.Text = (pageIndex += 1).ToString();

更多推荐

pageIndex,GridView,LinkButton,want,电脑培训,计算机培训,IT培训"/> <meta name=

本文发布于:2023-08-07 17:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   LinkButton   Repeater   Changing   Color

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!