what's the best way to bind multiple controls from different sections in the website to a single datasource ?
I'm also using masterpage , I thought I could add one there and use it all over , but that didin't work.
Need your help . .
Thank you
Printable View
what's the best way to bind multiple controls from different sections in the website to a single datasource ?
I'm also using masterpage , I thought I could add one there and use it all over , but that didin't work.
Need your help . .
Thank you
With ASP.NET, any object you add to a page is local to that page. You'll most likely have to copy the data source itself to each page and use it accordingly, which is a better practice. This way, you actually have control over each page individually.
Possibly the best practice would be to use ADO.NET and call a stored procedure in the database, avoiding data sources altogether. They're a good learning tool, but once you hit a certain point, they become unmaintainable. I'm now using stored procs for just about every database interaction I make. Very clean, and easy to maintain.
What about ObjectDataSource , I can use one and bind to it whatever controls too right?
I don't think you're understanding me. When it comes to ASP.NET, you can effectively think of every page as an individual application. Each has its' own set of events, controls, and variables. There are ways of transferring information between pages, but they aren't always 100% reliable. Your best bet as an ASP.NET beginner is to use a separate data source per page. You have better control over what happens, and it's cleaner in general.
http://www.vbforums.com/showthread.php?t=466658
That aside, don't treat web applications as you would a windows application. The process pipeline works differently.
You can however use the findcontrol() method to find the sqldatasource on different pages.
Code:dim ds as SqlDataSource = ctype(Page.Master.Findcontrol("SqlDataSource1"), SqlDataSource)