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. |
|||
|
|||
3 comments :
Good article.
How would you populate a dataset from an AccessDataSource ?
Excellent... thank's... so easy to understand...
Note: Only a member of this blog may post a comment.