GridView中获取UserControl
2009-08-04 09:53 Fred-Xu 阅读(378) 评论(0) 编辑 收藏 举报如果设计的UserControl中有公共的参数
/// <summary>
/// 缺陷ID
/// </summary>
public int DefectID
{
get;
set;
}
/// <summary>
/// 用例ID
/// </summary>
public int CaseID
{
get;
set;
}
/// <summary>
/// 是否为查看模式
/// </summary>
public bool IsView
{
get
{
object o = ViewState["IsView"];
return (o == null) ? false : (bool)o;
}
set
{
ViewState["IsView"] = value;
}
}
而UserControl嵌入在GridView中,一般情况下,直接用UserControl的ID来操作是不行的。解决方法如下:
//UserControl類別
public partial class Forms_Customer_WucCustomerStatement : System.Web.UI.UserControl
{
}
//在GridViewRow中取得使用者控制項,宣告的類別,其實就是自訂的UserContrl類別
Forms_Customer_WucCustomerStatement Wuc = (Forms_Customer_WucCustomerStatement)e.Row.FindControl("WucCustomerStatement1");//取得UserControl