0

I need to show the user in a grid the count of establishments that has each active status in the application. I already have the query but obviously it returns me 2 columns, one with the status name and one with the count. Should I use something like Pivot Columns in SQL Server and set the columns names and properties on the fly using row[0] or there is a better approach for what I need to do?

P.S. I am using Obout Grid to display the data.

<obout:Grid ID="gridStatus" runat="server" FolderStyle="~/obout/grid/styles/style_6"
            AllowAddingRecords="False" AutoGenerateColumns="False" AllowColumnReordering="True"
            PageSize="10" ShowTotalNumberOfPages="True" AllowManualPaging="True" AllowFiltering="True"
            AllowMultiRecordSelection="false"
            PageSizeOptions="10,20,30,40,50,100,500,999">
            <Columns>
                <obout:Column DataField="name" HeaderText="Status" />
                <obout:Column DataField="statusTotal" HeaderText="Total"/>
            </Columns>
            <ScrollingSettings ScrollWidth="100%" />
            <FilteringSettings FilterLinksPosition="TopAndBottom" FilterPosition="Top" />
        </obout:Grid>

But I can't use that format, the columns has to be each status.

Community
  • 1
  • 1
Edgar J. Rodriguez
  • 285
  • 1
  • 2
  • 13

1 Answers1

0

You can either pivot results of your query in backend SQL or, if it becomes to complicated - retrieve your 2-column data into .NET code and build a DataTable programmaticaly (create number of columns in the new DataTable according to number of rows in the result, name the columns according the "name" field and fill it with one row of data according to "statusTotal" field).

Then in your obout grid set AutoGenerateColumns="True" and do not specify <Columns></Columns>. This way grid will generate columns according to the datasource.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136