我的代码如下(asp.net2005)
For Each c As Control In Page.Controls
If TypeOf c Is TextBox Then
Select Case c.ClientID
Case "TextBox1"
DirectCast(c, TextBox).Text = "a1"
Case "TextBox2"
DirectCast(c, TextBox).Text = "a2"
Case "TextBox3"
DirectCast(c, TextBox).Text = "a3"
End Select
End If
Next不知道哪里出错,就是不能赋值。请各路高手指点
For Each c As Control In Page.Controls
If TypeOf c Is TextBox Then
Select Case c.ClientID
Case "TextBox1"
DirectCast(c, TextBox).Text = "a1"
Case "TextBox2"
DirectCast(c, TextBox).Text = "a2"
Case "TextBox3"
DirectCast(c, TextBox).Text = "a3"
End Select
End If
Next不知道哪里出错,就是不能赋值。请各路高手指点
解决方案 »
- 急急急!!!如何不用控件显示(比如用Lable显示),跪求CS,页面代码
- 请大家帮帮忙关于gridview的问题
- 请教:我在使用在线编辑器输入从Word复制的内容提交数据库时出错!
- 在ASP.NET使用javascript的一点小技巧
- 请教关于DATAGRID的模板列中CHECKBOX控件的问题
- ConnectionString 属性尚未初始化。
- asp.net显示柱状图数据的问题?
- 求助:关于实体集的转换问题
- 最简单的自定义控件的问题
- 关于在.net中附件存取的问题
- GridView一列要绑定到一个一对多的项,如何做,说的不太清楚,内详
- 关于Spreadsheet的问题.详细进进入.....
=====
For Each c As Control In Page.Form.Controls
{
if (cc.GetType() ==typeof(TextBox))
{
((TextBox)cc).Text = "aa";
}
}
For Each c As Control In Me.Controls
If c Is TextBox Then
Select Case c.ClientID
Case "TextBox1"
DirectCast(c, TextBox).Text = "a1"
Case "TextBox2"
DirectCast(c, TextBox).Text = "a2"
Case "TextBox3"
DirectCast(c, TextBox).Text = "a3"
End Select
End If
Next
string controlID = string.Empty;
for (int i = 0; i < this.Controls.Count; i++)
{
foreach (System.Web.UI.Control control in this.Controls[i].Controls)
{
if (control is TextBox)
{
controlID = (control as TextBox).ID;
string[] textBoxHeads = textBoxHead.Split(',');
for (int j = 0; j < textBoxHeads.Length; j++)
{
if (controlID.IndexOf(textBoxHeads[j]) == 0)
{
id = controlID.Substring(textBoxHeads[j].Length);
if (dt.ContainCol(id))
{
//try
//{
(control as TextBox).Text = dt.GetValue(id).Trim();
//}
//catch
//{
//}
}
}
} }
else if (control is HtmlInputHidden)
{
controlID = (control as HtmlInputHidden).ID;
string[] valueListHeads = hiValueHead.Split(',');
for (int j = 0; j < valueListHeads.Length; j++)
{
if (controlID.IndexOf(valueListHeads[j]) == 0)
{
id = controlID.Substring(valueListHeads[j].Length);
if (dt.ContainCol(id))
{
(control as HtmlInputHidden).Value = dt.GetValue(id).Trim();
}
}
}
}
else if (control is HtmlInputText)
{
controlID = (control as HtmlInputText).ID;
string[] valueListHeads = hiValueHead.Split(',');
for (int j = 0; j < valueListHeads.Length; j++)
{
if (controlID.IndexOf(valueListHeads[j]) == 0)
{
id = controlID.Substring(valueListHeads[j].Length);
if (dt.ContainCol(id))
{
(control as HtmlInputText).Value = dt.GetValue(id).Trim();
}
}
}
}
else if (control is DropDownList)
{
controlID = (control as DropDownList).ID;
string[] dropDownListHeads = dropDownListHead.Split(',');
for (int j = 0; j < dropDownListHeads.Length; j++)
{
if (controlID.IndexOf(dropDownListHeads[j]) == 0)
{
id = controlID.Substring(dropDownListHeads[j].Length);
if (dt.ContainCol(id))
{
(control as DropDownList).SelectedValue = dt.GetValue(id).Trim();
}
}
}
}
//(control as TextBox).Text = "";
}
}