I fetch data by using a selectmethod and it works fine , the problem is that I don't want a new table for each record inserted. I'd like a new column to be added to the existing table. Something like the picture below
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="FormView1" runat="server" ShowHeader="False" ItemType="MieleRepresentative.SteamBoiler" SelectMethod="GetSteamBoilerModels" RenderOuterTable="false" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table class="table-striped table-bordered">
<tr style="background-color: thistle!important;">
<td style="font-weight: bold;">Model</td>
<td><%# Eval("Model")%></td>
</tr>
<tr>
<td style="font-weight: bold">WorkingPressureLimit</td>
<td><%# Eval("WorkingPressureLimit")%></td>
</tr>
<tr>
<td style="font-weight: bold">TestPressureLimit</td>
<td><%# Eval("TestPressureLimit")%></td>
</tr>
<tr>
<td style="font-weight: bold">Electrical</td>
<td><%# Eval("Electrical")%></td>
</tr>
<tr>
<td style="font-weight: bold">Diameter</td>
<td><%# Eval("Diameter")%></td>
</tr>
<tr>
<td style="font-weight: bold">Height</td>
<td><%# Eval("Height")%></td>
</tr>
<tr>
<td style="font-weight: bold">Weight</td>
<td><%# Eval("Weight")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public IQueryable<SteamBoiler> GetSteamBoilerModels([QueryString("productID")] Guid productId)
{
var _mieleDbEntities = new MieleDBEntities();
return _mieleDbEntities.SteamBoilers.Where(boiler => boiler.FKProduct == productId);
}
If you want a table with an undefined number of columns (one for each record selected), probabily GridView is not your best bet.
In my opinion you should build dynamically your table in .aspx page in this way:
<% var steamBoilersList = GetSteamBoilerModels(...params...); %>
<table>
<!-- first row -->
<tr>
<% foreach (var singleSteamBoiler in steamBoilersList) { %>
<td>
<%= singleSteamBoiler.FIELD1 %>
</td>
</tr>
<!-- second row and so on -->
<tr>
<% foreach (var singleSteamBoiler in steamBoilersList) { %>
<td>
<%= singleSteamBoiler.FIELD2 %>
</td>
</tr>
</table>