例如:
<table id="thisTable">
<tr>
<td>
<asp:Button ID="btn_Save" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save1" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Savea" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Savex" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save6" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save3" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save2" runat="server" Text="保存模塊信息" Width="120px" />
</td>
</tr>
</table>因為按鈕是動態+上去的,我唯一知道的是類型(Button)
我想實現的是通過范圍(thisTable),類型(Button)
找出在thisTable里,類型是Button的所有控件id
不知道要怎么去實現,請教教我!!!!!!!!!
<table id="thisTable">
<tr>
<td>
<asp:Button ID="btn_Save" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save1" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Savea" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Savex" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save6" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save3" runat="server" Text="保存模塊信息" Width="120px" />
<asp:Button ID="btn_Save2" runat="server" Text="保存模塊信息" Width="120px" />
</td>
</tr>
</table>因為按鈕是動態+上去的,我唯一知道的是類型(Button)
我想實現的是通過范圍(thisTable),類型(Button)
找出在thisTable里,類型是Button的所有控件id
不知道要怎么去實現,請教教我!!!!!!!!!
解决方案 »
- AJAXPRO 再MVC里调用问题
- asp.net 生成静态页的问题
- 在web.config中配置的数据库连接,用完后要关闭吗?
- 还是Gridview
- 这样的2个Dropdownlist怎么联动?
- MultiPage与TabStrip在vs2005中出现的问题 代码如下为什么没法做像选项卡一样的效果谢谢
- 请教个存储过程
- 狂放分求助
- 项目合作:在线考试系统 ,类似于机动车驾使人考试用的那种。 要求用C# .net 开发。 最好找石家庄本地的朋友。 QQ:81675885 急~!具体情况加QQ后联系吧。
- 如何显示数据库中字段为image类型的图片到Image控件上面?在线等待,解决立即给分!!
- 关于.net(C#)XML文件的读取问题...在线等,急~~
- 页面传值问题
List<Button> list = new List<Button>();
private void SearchButton(Control ctrl)
{
foreach(Control c in ctrl.Controls)
{
if(c is Button)
{
Button btn = c as Button;
list.Add(btn);
}
else if(c.HasControls())
SearchButton(c);
}
}
using System;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
namespace Mail
{
public class FindControl
{
public FindControl()
{
}
public void Find(System.Web.UI.Control page)
{
int iPageControls = page.Controls.Count;
for (int i = 0; i < iPageControls; i++)
{
foreach (System.Web.UI.Control control in page.Controls)
{
if (control is Button)
{
(control as Button).Text="123";
}
if(control is HtmlTableCell)
{
Find(control as HtmlTableCell);
}
if(control is HtmlTableRow)
{
Find(control as HtmlTableRow);
}
}
}
}
}
}刚写的,没测试..
以下是我测试的方法,动态添加了六个CheckBoxList for (int i = 0; i < 6; i++)
{
CheckBoxList chk = new CheckBoxList();
chk.ID = "chk" + i;
ListItem lst=new ListItem("abc");
chk.Items.Add(lst);
form1.Controls.Add(chk);
}然后获取这六个动态添加的控件 for (int i = 0; i < form1.Controls.Count; i++)
{
if (form1.Controls[i].GetType()==typeof(CheckBoxList))
{
CheckBoxList radl = (CheckBoxList)(form1.Controls[i]);
}
}
我設置cbl_ParentModule.EnableViewState = true;
也沒效果