当前位置: 代码迷 >> ASP.NET >> 会输出控件类型吗
  详细解决方案

会输出控件类型吗

热度:7224   发布时间:2013-02-25 00:00:00.0
能输出控件类型吗?
比如要好多FindControl
有DropDownList的控件,有TextBox的控件,大部分获得控件再读控件上的text的代码是一样的,只有

string strTemp = (row.FindControl("ddl" + ColumnNames[i]) as DropDownList).Text.Trim();
string strTemp = (row.FindControl("tb" + ColumnNames[i]) as TextBox).Text.Trim();

有没有办法,把这里的 as 后面到底是哪种控件类型,写成一个代码


string strTemp = (row.FindControl(ctrlname) as (ctrlname.Find("ddl")? DropDownList:TextBox).Text.Trim();

------解决方案--------------------------------------------------------
C# code
string strTemp = (row.FindControl("ddl" + ColumnNames[i]) as ITextControl).Text
  相关解决方案