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.  

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
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 :)

# Issue in data binding for multiple objectdatasource

Left by Ranjit at 3/12/2010 5:10 PM
Gravatar
I have a second object data source to bind a dropdown. It depends upon the input parameter from the first dropdown's selectedvalue. The problem is - the second dropdown's datasource fails to read the value from first dropdown value. I see it as nothing in the input parameter of the method that forms the source of the obkject data.

Or, let me correct myself, it reads correctly on its own, but not earlier - like in page load.

# re: Refresh data in ObjectDataSource in button event handler

Left by Michael Freidgeim at 3/13/2010 5:15 PM
Gravatar
Ranjit,
It's probably depends on the order of events-you are trying to read it earlier than it is populated.
Consider to use Ajax Control Toolkit CascadingDropDown http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

# re: Refresh data in ObjectDataSource in button event handler

Left by John Gardner at 1/13/2011 9:59 AM
Gravatar
Thank you! This information kept me from pulling out what's left of my hair.

You rock, dude!

# re: Refresh data in ObjectDataSource in button event handler

Left by Tawhid at 1/15/2012 10:38 PM
Gravatar
when i write this code, data is not show in gridview. please give me any solution.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910