0
比方說,我有一個GridViewEx
類宣佈擴展GridView
。在該課堂內部,我有一個名爲GetDataPage
的代表。所以它看起來像這樣:GridView委託問題在ASP.Net
public class GridViewEx : GridView
{
public delegate object GetDataPageDelegate(int pageIndex, int pageSize, string sortExpression,
IList<FilterItem> filterItems);
[Browsable(true), Category("NewDynamic")]
[Description("Method used to fetch the data for this grid")]
public GetDataPageDelegate GetDataPage
{
get
{
return ViewState["pgv_getgriddata"] as GetDataPageDelegate;
}
set
{
ViewState["pgv_getgriddata"] = value;
}
}
// ... other parts of class omitted
}
這工作正常,做我想要的。不過,我想什麼能夠做的就是在標記爲GridViewEx,可以設置此委託,像這樣:
<div style="margin-top: 20px;">
<custom:GridViewEx ID="gridView" runat="server" SkinID="GridViewEx" Width="40%" AllowSorting="true"
VirtualItemCount="-1" AllowPaging="true" GetDataPage="Helper.GetDataPage">
</custom:GridViewEx>
</div>
不過,我得到這個錯誤:
Error 1 Cannot create an object of type 'GUI.Controls.GridViewEx+GetDataPageDelegate' from its string representation 'Helper.GetDataPage' for the 'GetDataPage' property.
我猜猜它不可能通過標記來設置,但我只是想知道。代碼中設置委託很容易,但我只是想學習新的東西。謝謝你的幫助。
只是一個問題,但您提供的委託對象要求其構造函數的參數?也許在該地區周圍的某些事情正在造成你的問 – 2010-07-02 16:38:16
我不認爲構造函數會影響它。我認爲可能只是用標記來設置委託,但我想我會問這裏只是爲了確定:)。 – dcp 2010-07-02 16:47:21
首先,如果您在標記中定義它的值,那麼使用viewstate是沒有意義的。 如果您正在動態設置值,則使用Viewstate,例如將它們與數據源綁定。 你在哪裏調用GetDataPage? – Jeroen 2010-07-02 18:33:10