如何在asp.net应用程序中添加for循环中的样式 [英] how to add styles in for loop in asp.net application

查看:56
本文介绍了如何在asp.net应用程序中添加for循环中的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有问题在for循环中添加样式。



我想要使用for循环打印10个名称。我想更改颜色的第8个数字名称。



下一页刷新我想动态更改颜色的下一个名字。我的意思是下一页加载我将更改颜色第二个数字名称。



这是我的代码更改:



Hi,

I have problem to add styles in for loop.

I want to print 10 names using for loop. I want to change color 8th number name.

Next page refreshing I want change the color next name dynamically. I mean next page load I will change color 2nd number name.

Here is my code changes:

int currentpg = 3;
int currentpage = 7;
int RowCount = 130;
for (int i = currentpg; i < (RowCount / 10); i++)
{
    LinkButton lnk = new LinkButton();
    if (currentpage != 0)
    {
        if (currentpg == currentpage)
        {
            lnk.Style.Add("fone-size", "14px");
            lnk.Style.Add("color", "red");
            //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 = " ";
    plcPaging.Controls.Add(spacer);
}





请帮助我。



谢谢。



Please Help me.

Thank you.

推荐答案

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

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


这篇关于如何在asp.net应用程序中添加for循环中的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆