如何更改动态标签名称 [英] How to change the dynamic label names

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

问题描述

在下面的代码中,我正在动态生成标签和文本框,我的问题是如何更改动态标签名称

Below code I am Dynamically generating Labels and textboxes, my Question is how to change the dynamic label names

private int numOfRows = 0;
        private int numOfColumns = 0;

        private void GenerateTable(int colsCount, int rowsCount)
        {

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

            
            for (int i = 0; i < rowsCount; i++)
            {
                TableRow row = new TableRow();
                for (int j = 0; j < colsCount; j++)
                {

                    
                    TableCell cell = new TableCell();
                    Label lbl = new Label();
                    lbl.Text = "label";
                    lbl.ID = "labelRow_" + i + "Col_" + j;
                    cell.Controls.Add(lbl);
                                    


                    TextBox tb = new TextBox();
                    tb.ID = "TextBoxRow_" + i + "Col_" + j;
                    cell.Controls.Add(tb);
                    row.Cells.Add(cell);
                    

                }

                table.Rows.Add(row);
            }
        }

推荐答案

for (int j = 0; j < colsCount; j++)
                {
 
                    
                    TableCell cell = new TableCell();
                    Label lbl = new Label();
                    lbl.Text = "label" + i;
                    lbl.ID = "labelRow_" + i + "Col_" + j;
                    cell.Controls.Add(lbl);
                                    
 

                    TextBox tb = new TextBox();
                    tb.ID = "TextBoxRow_" + i + "Col_" + j;
                    cell.Controls.Add(tb);
                    row.Cells.Add(cell);
                    
 
                }


这样,您可以更改标签的文本名称.
如果您想给不同的标签而不是使用switch case或if子句


In this way u can change the text name of the label.
If u want to give different to different labels than use switch case or if clause


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

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