且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net应用程序中添加for循环中的样式

更新时间:2023-02-24 23:25:42

所以将颜色移到循环外面,当计数器击中你的幻数时更改颜色:

So move the colour outside the loop, and change it when teh counter hits your "magic number":
string styleColour = "red";
for (int i = currentpg; i < (RowCount / 10); i++)
{
    if (i == magicNumber) styleColour = "green";
    LinkButton lnk = new LinkButton();
    if (currentpage != 0)
    {
        if (currentpg == currentpage)
        {
            lnk.Style.Add("fone-size", "14px");
            lnk.Style.Add("color", styleColour);


for (int i = currentpg; i < (RowCount / 10); i++)
            {
                
                LinkButton lnk = new LinkButton();
                if (currentpage != 0)
                {
                    if ((i+1) == currentpage)
                    {
                        lnk.Style.Add("fone-size", "14px");
                        lnk.Style.Add("color", "#10B1CA");
                        //lnk.Attributes.Add("Style", "color:#F24F09");

                        lnk.Font.Bold = true;
                    }
                }
            
                lnk.Click += new EventHandler(lbl_Click);
                lnk.ID = "lnkPage" + (i + 1).ToString();
                lnk.Text = (i + 1).ToString();
                plcPaging.Controls.Add(lnk);
                Label spacer = new Label();
                spacer.Text = "&nbsp;";
                plcPaging.Controls.Add(spacer);
            }