Set the controls to lightly toasted muffins... RSS 2.0
 Thursday, June 01, 2006

For some wierd reason my last post about how to create Subheadings using the GridView just won't syndicate, so for those of you who only use RSS/ATOM it's here http://blog.zygonia.net/PermaLink,guid,c093836d-8d97-4e5b-8a1c-8218742cb686.aspx.

 

Thursday, June 01, 2006 5:42:25 PM UTC  #    Comments [0] -

Yesterday I was working on a product list using the Gridview component and needed to render the list of products ordered by category. The list also had to have a subheading for the category of the product e.g.

It took a while to figure out but this article by Tim Heuer (there's a show/hide code at the bottom of the page) helped solve the problem. With a minor modification I got what I wanted.

I didn't require the sorting mechanism so I assigned the DataKeyNames property of the Gridview the names of the fields used to order the list before binding to the datasource so that I could pick out the category ID (line 71) in the controls overridden Render method:

    1         protected override void  Render(HtmlTextWriter writer)

    2         {

    3             Table table = (Table)this.productsGrid.Controls[0];

    4 

    5             int lastCategory = -1;

    6 

    7             foreach(GridViewRow row in productsGrid.Rows)

    8             {

    9                 int realIndex = table.Rows.GetRowIndex(row);

   10                 int currentCategory = Convert.ToInt32(this.productsGrid.DataKeys[row.RowIndex].Values[1]);

   11                 if(currentCategory != lastCategory)

   12                 {

   13                     GridViewRow groupHeaderRow =

   14                         new GridViewRow(realIndex, realIndex, DataControlRowType.Separator, DataControlRowState.Normal);

   15                     TableCell newCell = new TableCell();

   16                     newCell.ColumnSpan = this.productsGrid.Columns.Count;

   17                     newCell.BackColor = System.Drawing.Color.FromArgb(233, 229, 229);

   18                     newCell.ForeColor = System.Drawing.Color.DarkGray;

   19                     newCell.Font.Bold = true;

   20 

   21                     switch(currentCategory)

   22                     {

   23                         case 515:

   24                         case 517:

   25                             newCell.Text = "Home Products";

   26                             break;

   27 

   28                         default:

   29                             newCell.Text = "Business Products";

   30                             break;

   31                     }

   32 

   33                     groupHeaderRow.Cells.Add(newCell);

   34 

   35                     table.Controls.AddAt(realIndex, groupHeaderRow);

   36                     lastCategory = currentCategory;

   37                 }

   38             }

   39 

   40             base.Render(writer);

   41         }

 

Thursday, June 01, 2006 5:23:29 PM UTC  #    Comments [5] -
.NET
 Thursday, May 25, 2006

Yay! MS have a shiney new website just for IIS at http://www.iis.net. If I were you, my first port of call would be the .NET show interview with Bill Staples and Scot Guthrie where they show off some of the really cool features that are going to be part of IIS7.

Thursday, May 25, 2006 11:04:38 PM UTC  #    Comments [3] -
.NET | Techy
 Monday, May 22, 2006

Colin just pointed me at this from RedGate Software (via Scott Guthries blog). Works a treat in both SQL Server 2000 Query Analyser and SQL Server Management Studio.

Download it from here.

Monday, May 22, 2006 9:52:26 PM UTC  #    Comments [0] -

 Monday, May 15, 2006

Sparkplug (Dave) you're right about not expecting the ORDER BY clause to guarantee which results are returned by the TOP clause but in if you look at the execution plans for the view run on SQL 2000 and then on SQL 2005 we can see that SQL 2000 doesn't optimise out the ORDER BY:

Here's the view

create view [dbo].[testtop] as
select
top 100 percent * from prop_tbl_virtualtour order by propertyid

Here's the actual execution plan on SQL Server 2000 and we can see that the ORDER BY clause is honoured -

and this is the actual execution plan on SQL Server 2005, the ORDER BY is removed because TOP 100 PERCENT is returning all rows -

I'd say that's a breaking change, the behaviour in SQL Server 2000 is pretty consistent across a fairly wide selection of test cases.

Monday, May 15, 2006 6:54:20 PM UTC  #    Comments [1] -

Now Playing
Top Artists This Week
Fluff

Powered by FeedBurner
Categories
Archive
<June 2006>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Kevin Kenny
Sign In
Statistics
Total Posts: 194
This Year: 41
This Month: 0
This Week: 0
Comments: 101
All Content © 2008, Kevin Kenny
DasBlog theme 'Business' created by Christoph De Baene (delarou)