Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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.

VB
 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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900