我们如何在动态创建的表中访问动态创建的控件 [英] How we can access dynamic created control in dynamically created Table

查看:49
本文介绍了我们如何在动态创建的表中访问动态创建的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个asp桌子



//.aspx页面代码



I m create a asp table

//.aspx page code

<asp:Table ID="_tb" runat="server" style="border: 1px solid;" Width="80%"
                   GridLines="Both">
                   <asp:TableRow runat="server" BackColor="#3f3f3f">
                       <asp:TableCell Width="5%" style="color:white"><center>Sr No</center></asp:TableCell>
                       <asp:TableCell Width="30%" style="color:white"><center>Mid Station-Name</center></asp:TableCell>
                       <asp:TableCell Width="10%" style="color:white"><center>Status</center></asp:TableCell>
                   </asp:TableRow>
               </asp:Table>







然后即时创建动态行并在单元格中放置一些控件



//.cs页码



for(int i = 0;我< AllStat.Count; i ++)

{



TableRow tr = new TableRow();

tr.Style.Add( border,1px);

TableCell td1 = new TableCell();

td1.Attributes.Add(class,cent);

TableCell td2 = new TableCell();

td2.Attributes.Add(class,cent);

TableCell td3 = new TableCell( );

td3.Attributes.Add(class,cent);



td1.Text =(i + 1) .ToString();

tr.Cells.Add(td1);



标签lb =新标签();

string [] splt = AllStat [i] .Split('','');

lb.ID = splt [0];

lb. Text = splt [1] .ToString();

td2.Controls.Add(lb);

tr.Cells.Add(td2 ); $



DropDownList ddl = new DropDownList();

ddl.Items.Add(new ListItem(Select,0 ));

for(int j = 0; j< AllStat.Count; j ++)

{

ddl.Items.Add(new ListItem((j + 1).ToString(),(j + 10).ToString()));

}

td3.Controls.Add(ddl);

tr.Cells.Add(td3);

_tb.Rows.Add(tr);

}



但问题是我无法访问我在运行时创建的任何控件时间..



当我们计算此表中的行时,每次在.aspx页面上创建时,它只返回1行我想访问dynamicicall创建的下拉列表列表和标签文字..





谢谢。




then i m creating dynamically rows and put some control in cells

//.cs page code

for (int i = 0; i < AllStat.Count; i++)
{

TableRow tr = new TableRow();
tr.Style.Add("border", "1px");
TableCell td1 = new TableCell();
td1.Attributes.Add("class", "cent");
TableCell td2 = new TableCell();
td2.Attributes.Add("class", "cent");
TableCell td3 = new TableCell();
td3.Attributes.Add("class", "cent");

td1.Text = (i + 1).ToString();
tr.Cells.Add(td1);

Label lb = new Label();
string[] splt = AllStat[i].Split('','');
lb.ID = splt[0];
lb.Text = splt[1].ToString();
td2.Controls.Add(lb);
tr.Cells.Add(td2);

DropDownList ddl = new DropDownList();
ddl.Items.Add(new ListItem("Select","0"));
for (int j = 0; j < AllStat.Count; j++)
{
ddl.Items.Add(new ListItem((j+1).ToString(),(j+10).ToString()));
}
td3.Controls.Add(ddl);
tr.Cells.Add(td3);
_tb.Rows.Add(tr);
}

but th problem is that i cant access any control that i created at run time..

when we count yhe rows in this table it return only "1" row every time that creating on .aspx page here i want to access dynamicall created dropdown list and label text..


thanks.

推荐答案

试试在面板控件中获取动态创建的表值。
try to get your dynamically created table value in panel control.


这篇关于我们如何在动态创建的表中访问动态创建的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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