Gridview DataSourceID with Multiple Datasources?
I would like to display clickable news headlines. But I'm having trouble pulling data from two datasources for a single GridView. I'm trying to do this DataSourceID="SqlDataSource1, SqlDataSource2" but that's not working. Thanks开发者_StackOverflow in advance.
<asp:GridView
ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1, SqlDataSource2"
>
<Columns>
<asp:HyperLinkField
DataTextField = "NewsHeadline"
DataNavigateUrlFields="NewsURL"
/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="
<%$ ConnectionStrings:ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>"
SelectCommand="SELECT [NewsHeadline] FROM [NewsTable]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="
<%$ ConnectionStrings:ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>"
SelectCommand="SELECT [NewsURL] FROM [NewsTable]">
</asp:SqlDataSource>
A single control cannot use multiple sources.
You could create a custom data source control that accepts two data sources and produces output from both of them.
Why not use an SQL query that will select those 2 columns? Like:
SELECT [NewsHeadline], [NewsURL] FROM [NewsTable] WHERE 'something'
This way You will have one Datasource and problem will be solved :)
精彩评论