c#动态方法

来源:互联网 发布:js 替换所有html标签 编辑:程序博客网 时间:2024/05/06 08:35

1)c#根据一个传入的字符串得到需要使用的类

Type yourType =

Type.GetType("System.Web.UI.WebControls.Label");

Object yourLabel = Activator.CreateInstance(yourType);

2) Grid在程序中针对某行的动作E进行绑定:string fileLength = (string)DataBinder.Eval(e.Item.DataItem, "Size");

3)Grid动态寻找控件 :string fullPath = ((Label)item.FindControl("pathLabel")).Text;

注意,该FindControl在很多类中具有,意义相似。