databound datagrid to sql with rollup

J

js

I have a SQL Server 2003 stored procedure that uses "select ... group
by ... with rollup" syntax. The total of columns from the query varies
from 3 to 4. The query returns several rollup generated null column
rows. In an ASP.Net form, I have a datagrid.DataSource bound to the
query result from a DataReader. The grid has AutoGenerateColumns =
false. I manually add 1st and 2nd columns of the datagrid. The query
result is bound to columns starting at 3rd column. How do I program
the grid so that only the rows with all null (grand total) or one null
are displayed in the grid? I have the following code in the grid's
ItemDataBound event. Is there an easier way to do this? Filter the
result in SQL database query or use the Filter property in the
datagrid? Thanks.

private void MyDataGrid_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
try
{
byte byteSummaryColumnCount = 0;
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
for (byte byteGridCell =2; byteGridCell < e.Item.Cells.Count-1;
byteGridCell++)
{
if (e.Item.Cells[byteGridCell].Text == "All")
byteSummaryColumnCount++;
}
}
switch(e.Item.ItemType)
{
case ListItemType.AlternatingItem:
if (byteSummaryColumnCount != e.Item.Cells.Count - 3 &&
byteSummaryColumnCount != e.Item.Cells.Count - 4)
e.Item.Visible = false;
break;
case ListItemType.Item:
if (byteSummaryColumnCount != e.Item.Cells.Count - 3 &&
byteSummaryColumnCount != e.Item.Cells.Count - 4)
e.Item.Visible = false;
break;
}//end of switch
}
catch(Exception ex)
{
showMessage(ex);
}
}
 
J

js

Thanks for your interest. I got the problem solved by adding a
"HAVING" clause in the SQL statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top