Reputation: 4592
I have a database with two different tables, connected with one to many relationship. I would like to present values from table one together with fields refering to it from table two. I was trying to experiment with gridview and repeater control but did not manage to achieve any major success. Please help.
Upvotes: 0
Views: 127
Reputation: 17579
your code will help a lot. without it there is basically two options what you can do
first and fairly simple is to do one query to both tables, bind it to Sql DataSource and bind gridview or listview or other control bindable to enumerable.
ie
<asp:SqlDataSource ID="productDataSource" Runat="server"
SelectCommand="select t1.f1, t1.f2, ..... , t2.f1, t2.f2, ... from t1 inner join t2 on ..."
ConnectionString="your connection string">
</asp:SqlDataSource>
<asp:GridView ID="productsGridView" Runat="server"
DataSourceID="productDataSource" AutoGenerateColumns="True"></asp:GridView>
another (probably the right way to do it) is to adopt master detail scenario using two grid views for instance. you can find good example here
Upvotes: 2