Reputation: 576
I have a ObjectDataSource in which I was trying to pass some parameters.
GridDataSource.SelectMethod = "GetAllCountries";
GridDataSource.SelectParameters.Add("PageSize", pageSize.ToString());
GridDataSource.SelectParameters.Add("OrderBy", orderBy);
GridDataSource.SelectParameters.Add("StartIndex", startIndex.ToString());
and my method is in App_Code/DAL/CountriesDB.CS
public List<Countries> GetAllCountries(int PageSize,string OrderBy,int StartIndex)
{
..........
}
when I debugged it, in GetAllCountries Method PageSize=-1;OrderBy="",StartIndex=0 is passed...what is going on here??
thnx in advance...
Upvotes: 5
Views: 858
Reputation: 12523
I usually subscribe to the ObjectDataSource
's Selecting
event, where I can modify the InputParmeters
collection in ObjectDataSourceMethodEventArgs 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
Besides, the parameter values do not need to be strings. They should match the select method's parameters' types.
The select method must be specified either in code (just as you did in your question):
GridDataSource.SelectMethod = "GetAllCountries"; // code
... or in the markup:
<asp:ObjectDataSource ... SelectMethod="GetAllCountries" /> // markup
Upvotes: 0
Reputation: 69372
Handle the Selecting
event of GridDataSource
and enter your parameters there.
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());
}
Upvotes: 4
Reputation: 1082
You can try that way :
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);
Upvotes: 0