Asked by:
ListView Grouping

Question
-
User-1193791088 posted
I was unsure if this was a Sql Server or Data Control post - so here goes
I am creating a price list for services. i want to group them by ServiceId and have them print on separate pages.
Right now I have a Listview and Datasource for each ServiceId, but this doesn't help if when i have my project uploaded to the web if i add more Services and Id's.
What would be functional would be a ListView that would group them by ServiceId
This would also help for so many other reports as well
Or C# code behind solution would work
Current Example
<asp:ListView ID="ListView7" runat="server" DataSourceID="SDS_CS100" DataKeyNames="ItemId" > <AlternatingItemTemplate> <tr style=""> <td> <asp:Label Text='<%# Eval("Description") %>' runat="server" ID="DescriptionLabel" /></td> <td> <asp:Label Text='<%# Eval("ItemId") %>' runat="server" ID="ItemIdLabel" /></td> <td> <asp:Label Text='<%# Eval("PriceLevel1") %>' runat="server" ID="PriceLevel1Label" /></td> </tr> </AlternatingItemTemplate> <EditItemTemplate> <tr style=""> <td> <asp:Button runat="server" CommandName="Update" Text="Update" ID="UpdateButton" /> <asp:Button runat="server" CommandName="Cancel" Text="Cancel" ID="CancelButton" /> </td> <td> <asp:TextBox Text='<%# Bind("Description") %>' runat="server" ID="DescriptionTextBox" /></td> <td> <asp:Label Text='<%# Eval("ItemId") %>' runat="server" ID="ItemIdLabel1" /></td> <td> <asp:TextBox Text='<%# Bind("PriceLevel1") %>' runat="server" ID="PriceLevel1TextBox" /></td> </tr> </EditItemTemplate> <EmptyDataTemplate> <table runat="server" style=""> <tr> <td>No data was returned.</td> </tr> </table> </EmptyDataTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" /> <asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" /> </td> <td> <asp:TextBox Text='<%# Bind("Description") %>' runat="server" ID="DescriptionTextBox" /></td> <td> <asp:TextBox Text='<%# Bind("ItemId") %>' runat="server" ID="ItemIdTextBox" /></td> <td> <asp:TextBox Text='<%# Bind("PriceLevel1") %>' runat="server" ID="PriceLevel1TextBox" /></td> </tr> </InsertItemTemplate> <ItemTemplate> <tr style=""> <td> <asp:Label Text='<%# Eval("Description") %>' runat="server" ID="DescriptionLabel" /></td> <td> <asp:Label Text='<%# Eval("ItemId") %>' runat="server" ID="ItemIdLabel" /></td> <td> <asp:Label Text='<%# Eval("PriceLevel1") %>' runat="server" ID="PriceLevel1Label" /></td> </tr> </ItemTemplate> <LayoutTemplate> <table runat="server"> <tr runat="server"> <td runat="server"> <table runat="server" id="itemPlaceholderContainer" style="" border="0"> <tr runat="server" style=""> <th runat="server">Description</th> <th runat="server">ItemId</th> <th runat="server">PriceLevel1</th> </tr> <tr runat="server" id="itemPlaceholder"></tr> </table> </td> </tr> <tr runat="server"> <td runat="server" style=""></td> </tr> </table> </LayoutTemplate> <SelectedItemTemplate> <tr style=""> <td> <asp:Label Text='<%# Eval("Description") %>' runat="server" ID="DescriptionLabel" /></td> <td> <asp:Label Text='<%# Eval("ItemId") %>' runat="server" ID="ItemIdLabel" /></td> <td> <asp:Label Text='<%# Eval("PriceLevel1") %>' runat="server" ID="PriceLevel1Label" /></td> </tr> </SelectedItemTemplate> <ItemTemplate> <div class="row border-bottom print-row"> <asp:Label Text='<%# Eval("ItemId") %>' runat="server" ID="Label8" CssClass="d-block col-3" /> <asp:Label Text='<%# Eval("Description") %>' runat="server" ID="Label14" CssClass="d-block col-8" /> <asp:Label Text='<%# Eval("PriceLevel1","{0:C}") %>' runat="server" ID="Label9" CssClass="d-block col-1" /> </div> </ItemTemplate> </asp:ListView> </div> <asp:SqlDataSource ID="SDS_CS100" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 6) AND (CI.ServiceId = 100)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS519" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 519)"> </asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS501" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 501)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS502" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 502)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS503" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 503)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS520" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 520)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS700" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 700)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS713" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 713)"></asp:SqlDataSource> <asp:SqlDataSource ID="SDS_CS710" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1 FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3) AND (CI.ServiceId = 710)"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT CI.Description, CI.ItemId, SI.PriceLevel1, CI.ServiceId FROM CoItems AS CI INNER JOIN CoItems_Price_ServiceItem AS SI ON CI.ItemId = SI.ItemId WHERE (CI.ItemTypeId = 3)"></asp:SqlDataSource>
Perhaps a Nested ListView work around
Tuesday, January 1, 2019 5:18 PM
All replies
-
User283571144 posted
Hi RobertH3,
i want to group them by ServiceIdAccording to your description and codes,I don't know what is the rule of grouping the data by ServiceId.
If you want to dynamically generate the listview according to the serviceid, I suggest you could try to write the logic in the code-behind.
print on separate pagesI suggest you could use html CSS(page-break-after, page-break-before) to acheive your requirement.
Example HTML:
... content in page 1 ... <p style="page-break-after: always;"> </p> <p style="page-break-before: always;"> </p> ... content in page 2 ...
More details, you could refer to below article:
https://www.lvsys.com/how-to-add-page-breaks-to-html-in-articles
Best Regards,
Brando
Wednesday, January 2, 2019 9:38 AM -
User-2054057000 posted
You want Grouping but you haven't used Group By statement in your SQL Query. Apply your Group By statement in your asp:SqlDataSource control's SelectCommand property.
Thursday, January 10, 2019 11:03 AM