C# 遍历控件
来源:互联网 发布:百胜厨叻沙拉面 知乎 编辑:程序博客网 时间:2024/06/05 18:46
private DataSet GetData(ControlCollection oCtrls)
{
string[] strArray = new string[10];
string strTxtID = "";
Control oCtrl = oCtrls[0];
Control oCtrlTmp = null;
#region dtRtnResult
DataTable dtRtnResult = new DataTable("dtRtnResult");
dtRtnResult.Columns.Add("RtnType");
dtRtnResult.Columns.Add("RtnNo");
dtRtnResult.Columns.Add("RtnItem");
dtRtnResult.Columns.Add("RtnMat");
dtRtnResult.Columns.Add("RtnPrice");
dtRtnResult.Columns.Add("RtnQty");
dtRtnResult.Columns.Add("RtnAmount");
dtRtnResult.Columns.Add("RtnSumAmount");
for (int i = 0; i < 10; i++)
{
DataRow drTmp = dtRtnResult.NewRow();
//MoveType
strTxtID = "drpRtnType_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnType"] = ((DropDownList)oCtrlTmp).SelectedItem.Text;
//txtRtnNo_
strTxtID = "txtRtnNo_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnNo"] = ((TextBox)oCtrlTmp).Text;
//txtRtnItem_
strTxtID = "txtRtnItem_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnItem"] = ((TextBox)oCtrlTmp).Text;
//lblRtnMat_
strTxtID = "lblRtnMat_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnMat"] = ((Label)oCtrlTmp).Text;
//lblRtnPrice_
strTxtID = "lblRtnPrice_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnPrice"] = ((Label)oCtrlTmp).Text;
//txtRtnQty_
strTxtID = "txtRtnQty_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnQty"] = ((TextBox)oCtrlTmp).Text;
//lblRtnAmount_
strTxtID = "lblRtnAmount_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnAmount"] = ((Label)oCtrlTmp).Text;
//lblRtnSumAmount_
strTxtID = "lblRtnSumAmount_" + i.ToString();
oCtrlTmp = oCtrl.FindControl(strTxtID);
drTmp["RtnSumAmount"] = ((Label)oCtrlTmp).Text;
dtRtnResult.Rows.Add(drTmp);
}
{
string[] array = new string[4];
foreach (Control oCtrl in oCtrls)
{
int i=1;
while(i<=4)
{
string sID = "TextBox" + i.ToString();
Control oCtrl2 = oCtrl.FindControl(sID);
if ((oCtrl2 != null) && (oCtrl2 is TextBox))
{
((TextBox)oCtrl2).Text = array[i - 1].ToString();
}
else
{
SetData(oCtrl.Controls);
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SetData(this.Page.Controls);
}
利用递归寻找控件,那样控件层次放的再深也能找到
- C# 遍历控件
- C#页面遍历控件
- C#遍历控件
- C#遍历控件
- C# 遍历控件
- C# 控件遍历
- C# 遍历控件问题
- c# 遍历控件
- C#遍历控件
- C#控件遍历(获取控件名)
- C#中如何遍历窗口中的控件!
- treeView控件的使用(遍历) C#
- C# 遍历窗体上控件方法
- C#怎么遍历所有CHECKBOX控件
- C#中对控件的遍历
- C# Winform 遍历面板控件,写入XML
- 用C#如何遍历一个窗体中的某一种控件
- 如何遍历一个窗体中的某一种控件 c#实现
- N皇后问题(基本的搜索法)
- Oracle SQL性能优化技巧大总结
- 详细解说STL hash_map系列
- mount解决磁盘损坏
- linux下重启网络服务
- C# 遍历控件
- c# 订阅事件
- 黑客情书
- Ubuntu美化7.04,装了个Ubuntustudio主题
- ClientScriptManager类
- 试验网站#1搜索引擎优化收录情况记录(断续运行)2007-10-19
- 试验网站#3搜索引擎优化收录情况记录2007-10-19
- 配置管理资源列表
- 谈谈MD5的破解