Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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 on Wednesday, August 2, 2006 3:57 PM ASP.NET | Back to top


Comments on this post: Refresh data in ObjectDataSource in button event handler

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
thanks for this! i was very puzzled about it.
Left by tim on Jan 09, 2007 2:45 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thanks dude, this helped me out!!
Left by Gary Woodfine on Feb 15, 2007 1:45 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Seriously, that saved me an ulcer - thanks for this post.
Left by Darin See on Mar 16, 2007 3:35 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting 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.
Left by Bob Riley on Mar 21, 2007 4:26 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Bob Riley,

You are right. Call to ObjectDatasSource1.Select() is redundant.
Thanks for letting me know.
Michael.
Left by Michael Freidgeim on Mar 21, 2007 12:40 PM

# re: Refresh data in MovieClip
Requesting Gravatar...
may i get some help for this action
Left by abia on Nov 19, 2007 6:26 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
It saved me lots of research
Left by António Leite on Dec 08, 2007 10:41 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thanks for this post. Saved me some time.
Left by Arun George on Feb 02, 2008 7:49 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thanks a lot...
Left by Nitin on May 14, 2008 6:55 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Simply Superb man!!!!!!!!!!!!!!!!!!!
Left by Mahesh on Jun 23, 2008 6:36 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
You saved my a lot of time. thanks
Left by jj on Jul 31, 2008 8:12 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thanks Michel, its GREAT, I spent 2 days searching the solution, and finally this solved my problem,
Thanks a lot !!!
Left by Brij Mohan on Aug 18, 2008 5:07 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
greate, thanks for your help
Left by Lamla on Dec 08, 2008 7:04 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting 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 ?
Left by Hakeem on Jan 22, 2009 10:17 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Hi Hakeem,
I had similar issue before, see my VB.Net WebFormsHelper class function CurrentPageIndexAdjustIfRequired.
Left by Michael Freidgeim on Jan 23, 2009 8:24 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting 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.
Left by atefeh on Jul 26, 2009 5:36 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Good . Thank very very much . . . ..



Regards,
Prakash
Left by Prakash on Aug 15, 2009 12:47 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
MANY THAKS!! :D
Left by Boo on Aug 18, 2009 10:31 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thanks dude :)
Left by kornelius on Oct 28, 2009 11:50 AM

# Issue in data binding for multiple objectdatasource
Requesting 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.
Left by Ranjit on Mar 12, 2010 5:10 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting 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
Left by Michael Freidgeim on Mar 13, 2010 5:15 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thank you! This information kept me from pulling out what's left of my hair.

You rock, dude!
Left by John Gardner on Jan 13, 2011 9:59 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
when i write this code, data is not show in gridview. please give me any solution.
Left by Tawhid on Jan 15, 2012 10:38 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
thank u very much, i got good hint..
Left by jitendra on Oct 09, 2012 4:47 PM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
Thank you!!
Left by fechar on Aug 19, 2013 2:39 AM

# re: Refresh data in ObjectDataSource in button event handler
Requesting Gravatar...
I cant load page again its showing field not found error
Left by manz on Dec 02, 2014 6:08 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net