使用开关盒更改标签名称 [英] Change label names using switch case

查看:77
本文介绍了使用开关盒更改标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听到lbl.Text = i.ToString();在此行中的0,1,2 ...中运行时...
这些标签名称更改为使用开关的大小写.如何为这些0,1,2 ...编写开关盒...
如何更改名称.

Hear lbl.Text = i.ToString(); in this line runtime in 0,1,2 ... generated
these lable name change in to the use switch case. how to write switch case for these 0,1,2...
how to change the names.

 Table table = new Table();
            table.ID = "Table1";
            Page.Form.Controls.Add(table);


            for (int i = 0; i < 10; i++)
            {
                TableRow row = new TableRow();
                for (int j = 0; j < 1; j++)
                {


                    TableCell cell = new TableCell();
                    Label lbl = new Label();
                    lbl.Text = "Label " + i.ToString();
                    cell.Controls.Add(lbl);
                                       
switch (i)
{
  case 1:
  response.write("Case 1");
  break;
  case 2:
  response.write("Case 2");
  break;
  default:
  response.write("Default case");
  break;
}
                    
                    TextBox tb = new TextBox();
                    cell.Controls.Add(tb);
                    row.Cells.Add(cell);


                }

                table.Rows.Add(row);
            }

推荐答案

当您在多个列和行中添加标签时,只需追加"i"将重复名称/文本/标识(无论您想要哪个)

我建议您使用i +"_" + j,无需切换大小写,代码中给出了详细注释

As you are having label in muliple columns and rows just appending "i" will duplicate the name/text/id (whiche ever you want)

I would Suggest you using i + "_" + j , no need of switch case, detailed comment is given in the code

for (int i = 0; i < 10; i++) // Loop for Row
{
    TableRow row = new TableRow();
    for (int j = 0; j < 1; j++) // Loop for Column
    {
 
    //As you are having label in muliple columns and rows just appending "i" will duplicate the name/text/id (whiche ever you want)
    TableCell cell = new TableCell();
    Label lbl = new Label();
    lbl.Text = "Label " + i.ToString() + "_" + j.ToString(); // I would Suggest you using i + "_" + j no need of switch case
    cell.Controls.Add(lbl);
 
        //switch (i)
        //{
        //  case 1:
        //  response.write("Case 1");
        //  break;
        //  case 2:
        //  response.write("Case 2");
        //  break;
        //  default:
        //  response.write("Default case");
        //  break;
        //} 
    TextBox tb = new TextBox();
    cell.Controls.Add(tb);
    row.Cells.Add(cell); 
    } 
    table.Rows.Add(row);
} 



谢谢....请给5,如果这个回答您的问题.



Thanks.... Pls Rate 5,if this answer your question.


这篇关于使用开关盒更改标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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