Monday 14 May 2007

Gridview solution

I've found the solution to most of my problem!

The code for a standard gridview is listed below:

Protected Sub pubSearchResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles pubSearchResults.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim p As New Pub
p = e.Row.DataItem
Select Case p.award
Case 1
e.Row.Cells(1).Text = "Platinum"
Case 2
e.Row.Cells(1).Text = "Gold"
Case 3
e.Row.Cells(1).Text = "Silver"
Case 4
e.Row.Cells(1).Text = "Bronze"
End Select
Dim lnkEdit As New HyperLink
lnkEdit = e.Row.FindControl("lnkEdit")
'lnkEdit.NavigateUrl = "pubSearch_detail.aspx?id=" + p.id
End If
End Sub

The _RowDataBound method is a default gridview method and is called when every row in the grid is created. What I've done is accessed the row's award value (Which was collected from the row) and done a select case on it. From there, I've accessed the row passed in's cell index for the award. It's the second column in on the table, so it's the index 1. I've then assigned the text value Platinum, although I also intend to give it a css class to make it silver, which is just as simple to do.

No comments: