Refresh data in ObjectDataSource in button event handler

I have a user control with GridView and  ObjectDataSource. I also have a button, that should update database and I wanted to refresh GridView in the same click callback.

And it's easy to do- call ObjectDataSource.Select and then GridView.DataBind:

        Protected Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

 â€˜method to update database is omitted for simplicity

            Me.ObjectDataSource1.Select()

            Me.GridView1.DataBind()

        End Sub

Update: As I was adviced by Bob Riley, call to GridView1.DataBind()is enough.  

posted @ Wednesday, August 02, 2006 3:57 PM

Print

Comments on this entry:

# re: Refresh data in ObjectDataSource in button event handler

Left by tim at 1/9/2007 2:45 AM
Gravatar
thanks for this! i was very puzzled about it.

# re: Refresh data in ObjectDataSource in button event handler

Left by Gary Woodfine at 2/15/2007 1:45 AM
Gravatar
Thanks dude, this helped me out!!

# re: Refresh data in ObjectDataSource in button event handler

Left by Darin See at 3/16/2007 3:35 AM
Gravatar
Seriously, that saved me an ulcer - thanks for this post.

# re: Refresh data in ObjectDataSource in button event handler

Left by Bob Riley at 3/21/2007 4:26 AM
Gravatar
I don't think you need to call the ObjectDatasSurce1.Select(). Just the call to the GridView.Databind() will be fine (it will initiate the call to the select statement). I think, if you call both, the 'Select' method for the ObjectDataSource is also called twice.

# re: Refresh data in ObjectDataSource in button event handler

Left by Michael Freidgeim at 3/21/2007 12:40 PM
Gravatar
Bob Riley,

You are right. Call to ObjectDatasSource1.Select() is redundant.
Thanks for letting me know.
Michael.

# re: Refresh data in MovieClip

Left by abia at 11/19/2007 6:26 PM
Gravatar
may i get some help for this action

# re: Refresh data in ObjectDataSource in button event handler

Left by António Leite at 12/8/2007 10:41 AM
Gravatar
It saved me lots of research

# re: Refresh data in ObjectDataSource in button event handler

Left by Arun George at 2/2/2008 7:49 PM
Gravatar
Thanks for this post. Saved me some time.

# re: Refresh data in ObjectDataSource in button event handler

Left by Nitin at 5/14/2008 6:55 PM
Gravatar
Thanks a lot...

# re: Refresh data in ObjectDataSource in button event handler

Left by Mahesh at 6/23/2008 6:36 AM
Gravatar
Simply Superb man!!!!!!!!!!!!!!!!!!!

# re: Refresh data in ObjectDataSource in button event handler

Left by jj at 7/31/2008 8:12 AM
Gravatar
You saved my a lot of time. thanks

# re: Refresh data in ObjectDataSource in button event handler

Left by Brij Mohan at 8/18/2008 5:07 PM
Gravatar
Thanks Michel, its GREAT, I spent 2 days searching the solution, and finally this solved my problem,
Thanks a lot !!!

# re: Refresh data in ObjectDataSource in button event handler

Left by Lamla at 12/8/2008 7:04 PM
Gravatar
greate, thanks for your help

# re: Refresh data in ObjectDataSource in button event handler

Left by Hakeem at 1/22/2009 10:17 PM
Gravatar
hi how if u are on page2 and there is only one record.deleting that record is not redirecting to grids page1.

have anyone noticed that.

thanks,
any idea ?

# re: Refresh data in ObjectDataSource in button event handler

Left by Michael Freidgeim at 1/23/2009 8:24 AM
Gravatar
Hi Hakeem,
I had similar issue before, see my VB.Net WebFormsHelper class function CurrentPageIndexAdjustIfRequired.

# re: Refresh data in ObjectDataSource in button event handler

Left by atefeh at 7/26/2009 5:36 AM
Gravatar
how can i find Return Rows Count,if i don't call Select Method.
when Objectdatasource dosn't return any data,and then we use gridview.databind();
we give Error.i want to check in Button Click Event,if returns row is greater than 0 then bind grid.

# re: Refresh data in ObjectDataSource in button event handler

Left by Prakash at 8/15/2009 12:47 PM
Gravatar
Good . Thank very very much . . . ..



Regards,
Prakash

# re: Refresh data in ObjectDataSource in button event handler

Left by Boo at 8/18/2009 10:31 PM
Gravatar
MANY THAKS!! :D

# re: Refresh data in ObjectDataSource in button event handler

Left by kornelius at 10/28/2009 11:50 AM
Gravatar
Thanks dude :)

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345