Hi guys (and girls)
Thanks for taking time to help on this, please read the question before blindly pasting a link to a non related article you googled, I have taken time to look around (for days actually).
What I am trying to do
In a gridview I am creating a new dynamic column that has a 'swatch' in it (a div with set dimensions and a background colour that will change depending on a cells value). The 'swatch' works fine but it's at the end of the gridview
e.Row.Cells.Add(SwatchCell)
My Issue
where I am have big issues it trying to get the swatch
at the beginning of the gridview. Now I know you like code examples so I'll put down a cut down version of my GridView1_RowDataBound sub.
Here is a bastardisation of the code i have.
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim myDiv As HtmlGenericControl = New HtmlGenericControl("div")
myDiv.ID = "Swatch"
myDiv.InnerHtml = " "
myDiv.Style.Add("width", "15px")
myDiv.Style.Add("height", "15px")
myDiv.Style.Add("margin-left", "auto")
myDiv.Style.Add("margin-right", "auto")
Dim Swatchcolour As String = ""
Dim MyElapseTime As Integer = Int32.Parse(Replace(e.Row.Cells(8).Text, " hour(s)", ""))
Select Case MyElapseTime
Case 0
Swatchcolour = "Green"
Case 2 To 8
Swatchcolour = "Gold"
Case Is < 24
Swatchcolour = "Orange"
Case Else
Swatchcolour = "Red"
End Select
myDiv.Style.Add("background-color", Swatchcolour)
Dim SwatchCell As New TableCell
SwatchCell.Controls.Add(myDiv)
e.Row.Cells.Add(SwatchCell)
End Sub
any help would be greatly appreciated, as a note I can't add the swatch to the first cell as this holds the unique identifier and some code i picking up the value of that cell to use an 'onclick' function elsewhere
kind regards