multiple groupings of companies within asp.net report

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default multiple groupings of companies within asp.net report

    Hi all,

    The DataGrid (or reader) sure makes life easier for the vast majority
    of sql query display jobs but I've come across something that is almost
    making me wish for the old classic asp days. I'm not ready to start
    coding in the aspx page like a class asp'er yet so i'm hoping someone
    has some advice for me.

    My problem is that I need to show a report with the following pattern.
    The sql is easy but how to make it display nicely in a single (or
    variable number) datagrid control has me scratching my head.

    The desired result looks like this:

    Company A
    user x 20
    user y 30
    user z 10
    -----------------
    60

    Company B
    user c 14
    user d 5
    user e 23
    user f 100
    -----------------
    142

    Company C
    user k 1
    user l 39
    user w 30
    -----------------
    70


    So... displaying a single company in a datagrid would be easy but how
    do i display all three in a single datagrid with them grouped by
    company? There are a variable number of companies.

    The sql result I have looks something like this:

    Company A user x 20
    Company A user y 30
    Company A user z 10
    Company B user c 14
    Company B user d 5
    Company B user e 23
    Company B user f 99
    Company C User k 1
    Company C user l 39
    Company C user w 30

    Any help is much appreciated.

    karlid@yahoo.com Guest

  2. Similar Questions and Discussions

    1. Major companies using InDesign
      I've read that Wal-Mart and Starbucks use InDesign. What are some of the other major companies using it?
    2. DPI for a large Corregated Box. 200, 300 more??? Any templates? Companies to use that do it?
      Hi, I've been commissioned to design a large corrugated box for a product about the size of a 14" TV. I've done plenty of brochures and have used...
    3. Is it possible to create multiple PDF files from a single MS Access report run.
      I do a significant amount of reporting out of Microsoft Access databases and I an looking to increase our effeciency by utilizing PDF files for...
    4. Sorry about OT but what about web site promotion companies?
      Hi all. I keep getting email from a web site promotion company that promises to submit my site to 300,000 search engines. Their site looks good but...
    5. How to link 3 different combo boxex in a form (as report criteria) to the report
      I would like to use 3 combo boxes in a form as parameter criteria for a report. When I open a report, there will be a pop up form with 3 combo...
  3. #2

    Default Re: multiple groupings of companies within asp.net report

    Hi,

    You can use DataList (that loops thru Companies) + DataGrid (data source =
    DataView, set RowFilter for different company).

    HTH

    <karlid@yahoo.com> wrote in message
    news:1122358414.967570.63030@g44g2000cwa.googlegro ups.com...
    > Hi all,
    >
    > The DataGrid (or reader) sure makes life easier for the vast majority
    > of sql query display jobs but I've come across something that is almost
    > making me wish for the old classic asp days. I'm not ready to start
    > coding in the aspx page like a class asp'er yet so i'm hoping someone
    > has some advice for me.
    >
    > My problem is that I need to show a report with the following pattern.
    > The sql is easy but how to make it display nicely in a single (or
    > variable number) datagrid control has me scratching my head.
    >
    > The desired result looks like this:
    >
    > Company A
    > user x 20
    > user y 30
    > user z 10
    > -----------------
    > 60
    >
    > Company B
    > user c 14
    > user d 5
    > user e 23
    > user f 100
    > -----------------
    > 142
    >
    > Company C
    > user k 1
    > user l 39
    > user w 30
    > -----------------
    > 70
    >
    >
    > So... displaying a single company in a datagrid would be easy but how
    > do i display all three in a single datagrid with them grouped by
    > company? There are a variable number of companies.
    >
    > The sql result I have looks something like this:
    >
    > Company A user x 20
    > Company A user y 30
    > Company A user z 10
    > Company B user c 14
    > Company B user d 5
    > Company B user e 23
    > Company B user f 99
    > Company C User k 1
    > Company C user l 39
    > Company C user w 30
    >
    > Any help is much appreciated.
    >

    Elton Wang Guest

  4. #3

    Default Re: multiple groupings of companies within asp.net report

    Hi,

    Your suggestion sounds most promising but i'm unclear on the datagrid
    part. Would I be dynamically creating DataGrid objects for each
    company or is there a way to reuse one? Perhaps you know of a link to
    an article that describes this procedure?

    Cheers,

    karlid@yahoo.com Guest

  5. #4

    Default Re: multiple groupings of companies within asp.net report

    Hope following code is helpful


    <asp:DataList id="dataList" runat="server" RepeatDirection=Vertical
    BorderWidth="1">
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Company") %></br>
    <asp:DataGrid ID="datagrid" Runat=server ></asp:DataGrid>
    <hr>
    <%# DataBinder.Eval(Container.DataItem, "QTY") %></br>
    </ItemTemplate>
    </asp:DataList>

    Code:

    Load DataList:

    SqlDataAdapter dap = new SqlDataAdapter("Select Company, Sum(QTY) AS QTY
    FROM table_name GROUP BY Company",CONNECTION_STRING);
    DataTable companyTable = new DataTable();
    dap.Fill(companyTable);
    dap.Dispose();
    this.datLst.DataSource = companyTable;
    this.datLst.DataBind();


    In DataList_ItemDataBound event

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    DataGrid dgrd = (DataGrid)e.Item.FindControl("datagrid");
    dgrd.ShowHeader = false;
    DataRowView drv = (DataRowView)e.Item.DataItem;
    string connString = "server=(local);database=CustomData;Integrated
    Security=SSPI";

    string sql = "Select Customer, QTY from customers where Company =
    @company";
    SqlDataAdapter dap = new SqlDataAdapter(sql,connString);
    dap.SelectCommand.Parameters.Add("@company",
    drv["Company"].ToString().Trim());
    DataTable dataTable = new DataTable();
    dap.Fill(dataTable);

    dgrd.DataSource = dataTable;
    dgrd.DataBind();

    }



    <karlid@yahoo.com> wrote in message
    news:1122393109.085494.22720@z14g2000cwz.googlegro ups.com...
    > Hi,
    >
    > Your suggestion sounds most promising but i'm unclear on the datagrid
    > part. Would I be dynamically creating DataGrid objects for each
    > company or is there a way to reuse one? Perhaps you know of a link to
    > an article that describes this procedure?
    >
    > Cheers,
    >

    Elton Wang Guest

  6. #5

    Default Re: multiple groupings of companies within asp.net report

    Wow, thanks for the code samples. That basically solves the problem
    for me. Thanks very much.

    This whole thing has opened a whole new world to me. Now I see that
    you can nest databound controls wihin one another for some very nifty
    results.

    Thanks again!

    karlid@yahoo.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139