我有这个ASP.NET代码:

<asp:DropDownList
    ID="ddlBrokers"
    runat="server"
    AutoPostBack="true"
    DataSourceID="srcBrokers"
    DataTextField="broker"
    DataValueField="brokerId"
/>

<asp:ObjectDataSource
    id="srcBrokers"
    TypeName="DatabaseComponent.DBUtil"
    SelectMethod="GetBrokers"
    runat="server">
</asp:ObjectDataSource>


我的DAL代码:

public DataTable GetBrokers(bool? hasImport=null)
{
    SqlCommand cmd = new SqlCommand("usp_GetBrokers");
    if (hasImport.HasValue)
        cmd.Parameters.AddWithValue("@hasImport", hasImport);
    return FillDataTable(cmd, "brokers");
}


加载表单时,出现以下错误:

ObjectDataSource 'srcBrokers' could not find a non-generic method 'GetBrokers' that has no parameters.


是我的可选参数引起了问题吗?我该如何解决?声明性ASP.NET代码是否可以具有可选参数?

最佳答案

添加方法:

public DataTable GetBrokers() {
              return GetBrokers(null);
}


并检查是否有效?

10-06 01:08