A method for selecting an object data source that returns nothing when the code is called

I have ObjectDataSourcewith settings SelectMethodand SelectParameters. The data source is tied to a grid view that successfully displays page load data.

I need the ability to re-run a method Selectdefined ObjectDataSourcethat will be stored in a variable and manipulate the elements in it. The problem I am facing is that the method call .Select()always returns 0 rows, despite the fact that it fills the grid correctly.

Is there a reason why I cannot manually restart the method Select()in the object's data source?

Update 2:

This is how I configure ObjectDataSource:

myObjectDataSource.TypeName = typeof(MyDataAccessObject).ToString();
myObjectDataSource.SelectMethod = "GetBy" + stringVariable;
myObjectDataSource.SelectCountMethod = "GetCountBy" + stringVariable;
myObjectDataSource.EnablePaging = true;

Update 1:

Select() OnClick event:

protected void LinkButton1_Click(object sender, EventArgs e)
{
    SetupDataSource(); // populates the objSource SelectMethod, SelectParameters and TypeName etc.
    var items = objSource.Select();
    int count = items.Count(); // returns 0;
}

ObjectDataSource ( SelectMethod SelectParameters ) Page_Load.

ObjectDataSource :

<asp:ObjectDataSource ID="objSource" runat="server" EnablePaging="True" SortParameterName="sortExpression" ></asp:ObjectDataSource>

GridView :

        <asp:GridView 
        ID="myGridView" 
        runat="server" 
        DataSourceID="objSource"
        AllowPaging="true"
        ShowHeader="true" 
        AutoGenerateColumns="false"
        AllowSorting="true" 
        Width="100%" >
+3
3

, .Take(maximumRows), 0.

myObjectDataSource.EnablePaging = false;, , ( , ObjectDataSource ).

+1

, ( DataSource) .

Postback, Gridviews , viewstate. gridview ( init?) .

0

. , .Select() DataReader , Select , , .Select .Count() .

.ToList() , .

0

Source: https://habr.com/ru/post/1767054/


All Articles