views:

60

answers:

3

Hi, how Gridview co-operates with ObjectDataSource internally? When you set DataSourceID of GridView, assigned ObjectDataSource take care of such things as paging and sorting, but i don't have full control above databinding itself, on the other side when i set datasource of gridview in code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        testGridView.DataSource = testObjectDataSource.Select();
        testGridView.DataBind();
    }
}

Now i have full control, but i have lost the advantage of comfort sorting and paging. And that co-operation between ObjectDataSource and Gridview became mystery for me. So can anybody explain me in details how ObjectDataSource and Gridview co-operates under the hood? I want to understand it in order to write my own smart code or own gridview that will mimic this co-operation. Many thanks for answers.

A: 

You might need to take a look at this MSDN example. http://msdn.microsoft.com/en-us/library/aa479347.aspx. If you need more Edit and Insert options,look this example http://www.highoncoding.com/Articles/139_GridView%20With%20ObjectDataSource.aspx

Wonde
+1  A: 

I believe when you set the datasource in code behind all you do is give it data but no operational support. When you set the datasourceid you are providing the datasource to do the heavy lifting (inserting, filtering, sorting, etc...).

Please see if this http://forums.asp.net/t/1104728.aspx provides any more details.

----ADDED MORE INFO---- Here is some more detail on how to setup your own object datasource which should allow you see what is needed to make the operations like sort and filter and paging work. http://www.codeproject.com/KB/aspnet/ObjectDataSourceInDepth.aspx

MIchael Grassman
thanks, but it partially explains why is it so, but i still want to know how it works under the hood :)
sanjuro
If you truly want to see what it does, download reflector (from red gate) and peruse the code.
Chuck Conway
A: 

After long investigation i have discovered link that answers almost all of my questions: http://msdn.microsoft.com/en-us/library/system.web.ui.datasourceselectarguments.aspx

sanjuro