5

我有一个 ObjectDataSource,我试图在其中传递一些参数。

GridDataSource.SelectMethod = "GetAllCountries";
GridDataSource.SelectParameters.Add("PageSize", pageSize.ToString());
GridDataSource.SelectParameters.Add("OrderBy", orderBy);
GridDataSource.SelectParameters.Add("StartIndex", startIndex.ToString());

我的方法在 App_Code/DAL/CountriesDB.CS

public  List<Countries> GetAllCountries(int PageSize,string OrderBy,int StartIndex)
{
..........
}

当我调试它时,在 GetAllCountries 方法 PageSize=-1;OrderBy="",StartIndex=0 被传递...这是怎么回事?

thnx提前...

4

3 回答 3

4

处理Selecting事件GridDataSource并在那里输入您的参数。

protected void GridDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{    
    GridDataSource.SelectMethod = "GetAllCountries";            
    e.InputParameters.Clear();
    e.InputParameters.Add("PageSize", pageSize.ToString());
    e.InputParameters.Add("OrderBy", orderBy);
    e.InputParameters.Add("StartIndex", startIndex.ToString());         
}
于 2012-12-19T15:02:54.840 回答
0

你可以试试这样:

GridDataSource.SelectMethod = "GetAllCountries";
 Parameter p1 = new Parameter("PageSize",TypeCode.Int32);
 Parameter p2 = new Parameter("OrderBy",TypeCode.String);
 Parameter p3 = new Parameter("StartIndex",TypeCode.Int32);
 GridDataSource.SelectParameters.Add(p1);
 GridDataSource.SelectParameters.Add(p2);
 GridDataSource.SelectParameters.Add(p3);
于 2012-12-19T14:58:01.440 回答
0

我通常订阅ObjectDataSource'sSelecting事件,我可以在其中修改ObjectDataSourceMethodEventArgsInputParmeters中的集合:e

e.InputParameters["PageSize"] = pageSize; // pageSize is an int in your select method
e.InputParameters["OrderBy"] = orderBy;
e.InputParameters["StartIndex"] = startIndex; // startindex is an int too

此外,参数值不必是字符串。它们应该匹配 select 方法的参数类型。

select 方法必须在代码中指定(就像您在问题中所做的那样):

GridDataSource.SelectMethod = "GetAllCountries"; // code

...或在标记中:

<asp:ObjectDataSource ... SelectMethod="GetAllCountries" /> // markup
于 2012-12-19T15:00:30.420 回答