从表内的动态创建的文本框中检索文本 [英] Retrieve text from dynamically created text box inside a table

查看:85
本文介绍了从表内的动态创建的文本框中检索文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从面板内的表格中动态创建的文本框中检索文本。



我试过这个。我有一个列表(standardProperyList),其中包含数据库中的一些值。



How to Retrieve text from a dynamically created text box from a table inside a panel.

I have tried this. I have a list(standardProperyList) which contains some values from database.

Table table = new Table();

            for (int i = 0; i <= standardProperyList.Count-1; i++)
            {

                TableRow row = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell2 = new TableCell();

                Label lbl = new Label();
                TextBox TxtBox = new TextBox();

                lbl.ID = "lbl" + standardProperyList[i].PropertyName.ToString();
                TxtBox.ID = "txt" + standardProperyList[i].PropertyName.ToString();

                ListTestBoxIds.Add(TxtBox.ID);

               
                cell1.ID = "cellPropertyName" + i.ToString();
                cell2.ID = "cellPropertyValue" + i.ToString();

                lbl.Text = standardProperyList[i].PropertyName.ToString();
                TxtBox.Text = standardProperyList[i].PropertyValue.ToString();

                cell1.Controls.Add(lbl);
                cell2.Controls.Add(TxtBox);
                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                table.Rows.Add(row);

                //Add the labels and textboxes to the Panel.
                PanelStandardProperties.Controls.Add(table);

                TextBox tt = (TextBox)table.FindControl(TxtBox.ID);
                string tes = tt.Text;

                Tried this as well.
                //foreach (Control c in PanelStandardProperties.Controls)
                //{
                //    if (c is TextBox)
                //    {
                //        TextBox txt = (TextBox)c;
                //        string str = txt.Text;
                //    }
                //}


            }





得到以下错误



找到了具有相同IDlblARPCOMMENTS的多个控件。 FindControl要求控件具有唯一ID。



请协助



先谢谢你



Am getting below mentioned error

Multiple controls with the same ID 'lblARPCOMMENTS' were found. FindControl requires that controls have unique IDs.

Please Assist

Thanks in Advance

推荐答案

如果你在standardProperyList中有重复值,那么

If you have duplicate value in standardProperyList then
lbl.ID = "lbl" + standardProperyList[i].PropertyName.ToString();



此行将生成相同的标签ID。你可以改变类似


this line will generate same Label ID. You could change something like

lbl.ID = "lbl" + standardProperyList[i].PropertyName.ToString() + i; 





这里i将添加一个带有ID的数字,例如lblARPCOMMENTS1



Here "i" will add a number with the ID such as "lblARPCOMMENTS1"


让你控制id独特,参考这篇文章,

找到具有相同ID的多个控件
Hi, make you control ids unique, refer this article,
Multiple controls with the same ID were found


这篇关于从表内的动态创建的文本框中检索文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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