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 !!!

Your comment:



 (will not be displayed)


 
 
 
Please add 3 and 6 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910