关于循环给控件负值错误~~~急
for(int i=0;i<=2;i++)
{
int tp=i+1;
OleDbCommand objCommand = new OleDbCommand("select * from 文字 where 位置='index"+ tp +"'" , objConnection);
objConnection.Open();
OleDbDataReader objDataReader=objCommand.ExecuteReader();
if(objDataReader.Read())
{
string lcID="lable"+i*3+1;
foreach(WebControl webControl in this.Controls)
{
if(webControl is Label && webControl.ID == lcID)
{
webControl.Text = Convert.ToString(objDataReader["标题"]);
}
}
}
}
错误提示:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0117: 'System.Web.UI.WebControls.WebControl' does not contain a definition for 'Text'
Source Error:
Line 47: if(webControl is Label && webControl.ID == lcID)
Line 48: {
Line 49: webControl.Text = Convert.ToString(objDataReader["标题"]); **错误行
Line 50: }
Line 51: }
问题点数:20、回复次数:3Top
1 楼birdxxxx(爱上老鼠的猫)回复于 2005-08-04 00:34:21 得分 10
if(webControl is Label && webControl.ID == lcID)
{
(Label)webControl.Text = Convert.ToString(objDataReader["标题"]); **错误行
}
//没在代码里验证,你试一下。我是看错误来做的,错误里面说明了WebControl里没有Text这个定义Top
2 楼zhilunchen(他山居士)回复于 2005-08-04 01:28:53 得分 5
if(webControl is Label && webControl.ID == lcID)
{
((Label)webControl).Text = Convert.ToString(objDataReader["标题"]); **错误行
}Top
3 楼hchxxzx(NET?摸到一点门槛)回复于 2005-08-04 08:48:49 得分 5
错误实际上在这一句
foreach(WebControl webControl in this.Controls)
在asp.net中,当前的窗体,实际上并非即为form,this.Controls实际上包含三个对象:form之前的页面头部对象,form对象,form对象之后的页面底部。
所以上述语句应该改为:
foreach(WebControl webControl in this.Controls[1].Controls)Top




