在Repeater中改变LinkBut​​ton的颜色

时间:2013-10-08 20:58:40

标签: c# asp.net css visual-studio-2010 linkbutton

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

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

提前致谢。

2 个答案:

答案 0 :(得分:0)

在点击处理程序中设置ForeColor的{​​{1}}属性,如下所示:

LinkButton

答案 1 :(得分:0)

我用不同的方式解决了它,使用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();