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: }
if(webControl is Label && webControl.ID == lcID)
{
if(webControl is Label && webControl.ID == lcID)
{
((Label)webControl).Text = Convert.ToString(objDataReader["标题"]); **错误行
}
错误实际上在这一句
foreach(WebControl webControl in this.Controls)
在asp.net中,当前的窗体,实际上并非即为form,this.Controls实际上包含三个对象:form之前的页面头部对象,form对象,form对象之后的页面底部。
所以上述语句应该改为:
foreach(WebControl webControl in this.Controls[1].Controls)