I have a site with a number of gridview's and want to add more client side function. I am trying to understand how to bind a gridview with jQuery. As best I can understand it, a jQuery function will need to interact with a webservice to populate the gridview? Is there anyway for jQuery to interact with subs in the code-behind of the webpage?
-
why not use updatepanel control to load the gridview on demand?krishna– krishna2011-02-24 17:51:57 +00:00Commented Feb 24, 2011 at 17:51
-
I use the update panel in some cases but like I mentioned in another comment, I would like to off-load the populating of gridviews until after page load. I thought jQuery would help me work that magic!IMAbev– IMAbev2011-02-24 17:55:10 +00:00Commented Feb 24, 2011 at 17:55
-
1You can still do that with UpdatePanels. Set the internal content to Visible=false, then call __doPostBack('updatepaneluniqueid','true') (for example - the 2nd parameter will be used by your code to decide the contents should be visible) when page loading is complete to render them. I could see in a very content-heavy page this might be useful to better control the order in which things are rendered.Jamie Treworgy– Jamie Treworgy2011-02-24 17:57:37 +00:00Commented Feb 24, 2011 at 17:57
-
1Also if you're not doing this already, enable CDN in your ScriptManager which will cause all the MS scripts to be referenced from Microsoft's CDN instead of your server. It's good for the internet and will take load off your server, but unless bandwidth is a problem it probably won't cure your slow pages.Jamie Treworgy– Jamie Treworgy2011-02-24 18:07:24 +00:00Commented Feb 24, 2011 at 18:07
2 Answers
This is kind of apples and oranges. If you use jQuery to populate your grid from the client, then you aren't really using a GridView any more, except, perhaps, as a template.
But basically, if you wanted to use client-side code to populate and manage the contents of a a grid that is based on a large server-side database, you'll be running ajax queries from the client for every event that needs new data (such as paging) and rebuilding/repopulating the grid.
jQuery interacts with server code through ajax. So any information you need at the client will have to come from something on the server designed specifically to provide that information: a WebService, WebMethod, or dedicated page that can be queried with GET and returns html.
This is certainly doable, but why do you want to do this? All your functionality already exists, and it's generally more work to make something with heavy client/server interaction work entirely from javascript, even if starting from scratch. But there's nothing stopping you from using jQuery to decorate and add new functionality to your existing server-based grids.
2 Comments
Why do you want to do this? Are you experiencing performance problems? In this case, you should consider reeveluating your data fetching methods.