Im following a guide.....The autor uses SQLDataSource1 to display data in a gridview (lets say an artist and his album) then he creates SqlDataSource2 to bound to a drop down list which only lists the albums by an artist. Auto post back is enabled so whenever i click an artists name it only returns their albums.
My question is simply why use 2 SQLDatasource - when would you need to use 2 datasources?
Thanks
If you notice those datasources there, you will probably find that their select parameters are different. Your first datasource has probably no filter at all in it's select statement, but your second datasource has probably a filter by artist in its select statement. So, you do not want a filter to be used with the datagrid, but you need a filter to be used with the dropdown. Sice this "filter" is not set in the client controls (the datagridview and dropdown don't even know what a "filter" is), but in the datasources, you need two different datasources, one for each case you have.
Just try combining those two datasources, and see the mess you'll end up with lol.
Hope it helps,
Jorge
Thanks for that. It makes some sense. Yes your right he did have a filter on the second SQLSource but the first had none.
As a general rule when should you have 2 SqlDataSources? i.e. whenever you want to filter data?
Thanks
I would prefer to use the single SQLDataSource for the DDL and GridView with the following SQLStatement.
CREATE PROCEDURE dbo.usp_Album_Select
@.Artist Varchar(50)
AS{
SELECT * FROM Album WHERE Artist = COALESCE(@.Artist, Artist)
}
Hi EssCee,
Based on my understanding, you did a simple project following an article. And you want to know why and when use multiple SqlDataSource in one page. If I have misunderstood you, please feel free to let me know.
The SqlDataSource control enables you to use a Web control to access data sources. You can use the SqlDataSource control with other controls that display data, such as the GridView, FormView, and DetailsView controls, to display and manipulate data on an ASP.NET Web page, using little or no code. Generally, the control be used to display data has one DataSource Control. In your case, there are two controls be used to display different data. So there are two SqlDataSources. But sometimes multiple controls maybe have one dataSource Control; hence they have the same DataSource.
Sometimes, there are many data be selected from database. But you want to display the data you want to display. So you need to filter the data.
It is hard to say that why or when use DataSource Control and when you should filter data. You should work by your requirements.
I hope this helps.
0 comments:
Post a Comment