双系统安装教程linux:大家帮我改改这句ASP。NET的C#程序

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 21:03:12
for(i=2;i<NumCols-2;i++)
{ TextBox CurrentTextBox;
CurrentTextBox=e.Item.Cells[i].Controls[0];
string ColValue=CurrentTextBox.Text;
}
错误是:编译器错误信息: CS0029: 无法将类型“System.Web.UI.Control”隐式转换为“System.Web.UI.WebControls.TextBox”
应该怎么改?急

for(i=2;i<NumCols-2;i++)
{
    TextBox CurrentTextBox;
    CurrentTextBox=(TextBox)e.Item.Cells[i].Controls[0];
    string ColValue=CurrentTextBox.Text;
}

CurrentTextBox=e.Item.Cells[i].Controls[0];
应该改为
CurrentTextBox=(TextBox)e.Item.Cells[i].Controls[0];

需要强制转换
完整的程序:
for(i=2;i<NumCols-2;i++)
{
TextBox CurrentTextBox;
CurrentTextBox=(TextBox)e.Item.Cells[i].Controls[0];
if(CurrentTextBox!=null)
{
string ColValue=CurrentTextBox.Text;
}
}