Click here to Skip to main content
15,887,815 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello there...
I want to show in one gridview one item from one sqldatasource(first), one item from a second datasource and one other item from another (third)datasource. Any idea how it can be shown three sqldatasources in one gridview?

This is just an example:
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="ID">
    <Columns>            
        <asp:BoundField DataField="item1" HeaderText="item1"></asp:BoundField>
        <asp:BoundField DataField="item2" HeaderText="item2"></asp:BoundField>
        <asp:BoundField DataField="item3" HeaderText="item3"></asp:BoundField> <Columns></asp:GridView>

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ConnectionStrings:ConnectionString1 %>' SelectCommand="SELECT item1 from table1"</asp:SqlDataSource>    
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString1 %>' SelectCommand="SELECT item2 from table2"</asp:SqlDataSource> 
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString1 %>' SelectCommand="SELECT item3 from table3"</asp:SqlDataSource>
Posted

1 solution

If they have a 1 = 1 = 1 relationship, then combine the queries (datasources) to give you one result set back.

If these are 3 disparate data sets, then you'll need three different gridviews, but you can put them all in one table.

A datagrid is similar to a database table, each row corresponds to columns of related data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900