I have an ObjectDataSource
with the proper SelectMethod
and SelectParameters
configured. The data source is bound to a grid view which successfully displays the data on page load.
What I need is the ability to rerun the Select
method defined by the ObjectDataSource
to be stored in a variable and manipulate the items in it. The issue I keep encountering is that calling the .Select()
method always returns 0 rows despite it populating the grid view properly.
Is there a reason I can't manually rerun the Select()
method on the object data source?
Update 2:
Here is how I setup the ObjectDataSource
:
myObjectDataSource.TypeName = typeof(MyDataAccessObject).ToString();
myObjectDataSource.SelectMethod = "GetBy" + stringVariable;
myObjectDataSource.SelectCountMethod = "GetCountBy" + stringVariable;
myObjectDataSource.EnablePaging = true;
Update 1:
I run the Select()
on a link button's OnClick
event:
protected void LinkButton1_Click(object sender, EventArgs e)
{
SetupDataSource(); // populates the objSource's SelectMethod, SelectParameters and TypeName etc.
var items = objSource.Select();
int count = items.Count(); // returns 0;
}
The ObjectDataSource is setup (SelectMethod and SelectParameters are set) in the Page_Load
event.
ObjectDataSource
definition:
<asp:ObjectDataSource ID="objSource" runat="server" EnablePaging="True" SortParameterName="sortExpression" ></asp:ObjectDataSource>
GridView
definition:
<asp:GridView
ID="myGridView"
runat="server"
DataSourceID="objSource"
AllowPaging="true"
ShowHeader="true"
AutoGenerateColumns="false"
AllowSorting="true"
Width="100%" >