locked
Web Forms C# - Multiple Select Query Results in a GridView?? RRS feed

  • Question

  • User-1575818943 posted

    Edited

    Wednesday, September 13, 2017 5:20 AM

Answers

  • User-335504541 posted

    Hi knnth192o,

    Can I use a data control like GridView or Repeater?

    Yes, you can.

    For example:

              <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField HeaderText="item" DataField="Item"/>
                        <asp:BoundField HeaderText="Manufacturer" DataField="Manufacturer"/>
                        <asp:BoundField HeaderText="Price" DataField="Price"/>
                        <asp:BoundField HeaderText="Average Sold Price" DataField="AverageSoldPrice"/>
                        <asp:BoundField HeaderText="Total Sold" DataField="TotalSold"/>
                        <asp:BoundField HeaderText="Inventory" DataField="Inventory"/>
                        <asp:BoundField HeaderText=" Qty In Wishlist" DataField=" QtyInWishlist"/>
                        <asp:BoundField HeaderText="Sales Rank" DataField="SalesRank"/>
                        <asp:BoundField HeaderText="Qtr1" DataField="Qtr1"/>
                        <asp:BoundField HeaderText="Qtr2" DataField="Qtr2"/>
                        <asp:BoundField HeaderText="Qtr4" DataField="Qtr4"/>
                    </Columns>
                </asp:GridView>

    And you could bind the data in behind code:

            protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = GetData();
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

    I don't think one single query can generate a report like this.

    Have you try to use join ? Or you could try to use code to merge the tables in behind code.

    Could you show me your tables and your sql query or the result of your each query so that I can help you?

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 13, 2017 8:27 AM

All replies

  • User-335504541 posted

    Hi knnth192o,

    Can I use a data control like GridView or Repeater?

    Yes, you can.

    For example:

              <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField HeaderText="item" DataField="Item"/>
                        <asp:BoundField HeaderText="Manufacturer" DataField="Manufacturer"/>
                        <asp:BoundField HeaderText="Price" DataField="Price"/>
                        <asp:BoundField HeaderText="Average Sold Price" DataField="AverageSoldPrice"/>
                        <asp:BoundField HeaderText="Total Sold" DataField="TotalSold"/>
                        <asp:BoundField HeaderText="Inventory" DataField="Inventory"/>
                        <asp:BoundField HeaderText=" Qty In Wishlist" DataField=" QtyInWishlist"/>
                        <asp:BoundField HeaderText="Sales Rank" DataField="SalesRank"/>
                        <asp:BoundField HeaderText="Qtr1" DataField="Qtr1"/>
                        <asp:BoundField HeaderText="Qtr2" DataField="Qtr2"/>
                        <asp:BoundField HeaderText="Qtr4" DataField="Qtr4"/>
                    </Columns>
                </asp:GridView>

    And you could bind the data in behind code:

            protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = GetData();
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

    I don't think one single query can generate a report like this.

    Have you try to use join ? Or you could try to use code to merge the tables in behind code.

    Could you show me your tables and your sql query or the result of your each query so that I can help you?

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 13, 2017 8:27 AM
  • User-1575818943 posted

    Edited

    Wednesday, September 13, 2017 4:28 PM
  • User-1575818943 posted

    Edited

    Thursday, September 14, 2017 5:04 AM
  • User-335504541 posted

    Hi knnth192o,

    What should I do if I need to use 3 different select queries to get the result I want?

    You could try use c# code in behind to merge 3 result.

    What's the results? Is there any connection between them?

    Best Regards,

    Billy

    Thursday, September 14, 2017 6:17 AM
  • User-1575818943 posted

    Deleted

    Thursday, September 14, 2017 4:33 PM
  • User-1575818943 posted

    Deleted

    Sunday, September 17, 2017 12:37 AM