Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Introduction:

Here I will explain how to bind dataset with objectdatasource data using asp.net

Description:

Here we need to remember that if we bind our gridview with objectdatasource that objectdatasource fill with data only whenever gridview databind is called like this 

gridview1.DataBind()=ods (ods is ObjectDataSource);


Why I have talk about this means now we are going to write function to bind dataset with objectdatasource data. We need to call this function only after gridview databind because if we call this method before the objectdatasource load with data we will get error that’s why I mention regarding this one.

Now we need to write function like this in code behind 

private DataSet GetDS(ObjectDataSource ods)
{
var ds = new DataSet();
var dv = (DataView)ods.Select();
if (dv != null && dv.Count > 0)
{
var dt = dv.ToTable();
ds.Tables.Add(dt);
}
return ds;
}
After execution of this function check dataset data it will bind with objectdatasource data

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Anonymous said...

Good article.
How would you populate a dataset from an AccessDataSource ?

Anonymous said...

Lelouch Kei said...

Excellent... thank's... so easy to understand...

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.