A Simple way to span column headers in an asp.net Gridview

Posted by admin on June 19, 2009 under 4-Code snippets | Read the First Comment

Let’s say you have an asp.net gridview and you want to group or span several columns under the same heading. For example, you are displaying quarterly sales data:

Customer Rep Q1 Sales Q2 Sales Q3 Sales Q4 Sales
Acme Tools John Smith 4500 4400 4600 4100
Mega Motors Anne Tyler 9790 9670 9540 8900

But what you really want to show is:

  Sales
Customer Rep Q1 Q2 Q3 Q4
Acme Tools John Smith 4500 4400 4600 4100
Mega Motors Anne Tyler 9790 9670 9540 8900

If your Gridview is called grdSales, there is an easy way to do this in the code behind. Create an event for row_created, then put this in:

Protected Sub grdSales_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdSales.RowCreated

If e.Row.RowType = DataControlRowType.Header Then

Dim oGridView As GridView = DirectCast(sender, GridView)

Dim oGridViewRow As New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)

Dim oTableCell As New TableCell()

oTableCell.Text = “”

oTableCell.ColumnSpan = 2

oTableCell.BackColor = Drawing.Color.White

oGridViewRow.Cells.Add(oTableCell)

oTableCell = New TableCell()

oTableCell.Text = “Sales”

oTableCell.HorizontalAlign = HorizontalAlign.Center

oTableCell.ColumnSpan = 4

oGridViewRow.Cells.Add(oTableCell)

 oGridView.Controls(0).Controls.AddAt(0, oGridViewRow)�
End If

 End Sub

 If you found my post helpful and it saved you time or money, please contribute by making a small donation. Even a dollar or two adds up!

Readable file record segment is not writeable

Posted by admin on June 11, 2009 under 3-Tech Tips | Be the First to Comment

After one of the many times my Vista Business 32 laptop locked up, it didn’t recover too gracefully. On bootup I got the infamous “One of your disks needs to be checked…” errors. That was the good news. The bad news was that chkdsk would not complete running on startup. During stage one, I got the message: Deleting corrupt attribute record …. from file record segment … Readable file record segment 60195 is not writeable.

No matter how I tried to run chkdsk, it would not complete. I ran a disk sector test and the hard drive came out clean. I ran Norton Disk Doctor and it did nothing. Extensive googling on the error yielded little, so I tried googling on various parts of the error phrases.

In the end, it turned out the solution was pretty simple. Apparently, even when running chkdsk on startup, the C: drive may be locked. So I booted to the recovery CD, which had a command prompt option. Then running good old-fashioned chkdsk C: /f from the DOS prompt fixed my drive.