Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating the Cell Color in a datagrid on a webform
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Titre:
Updating the Cell Color in a datagrid on a webform
Divers
Thread ID:
00672063
Message ID:
00672063
Vues:
47
I have a calendar and basic datagrid on a webform. When the user clicks on a date in the calendar, I execute a stored procedure to return a result set. I then bind this to the datagrid and display it, so far so good. The sp result set has one row for each room, so the number of rows will vary, but it will always have the same number of columns. Each column will have either a 0 (zero) or 1 (one). If it is a zero, I want to set the cell color to green and if it is a 1 I want to set it to red. So my question is, how can I loop through the grid rows and check each value and modify it. Here is what I have so far:
        'Bind the data
        Me.DataGrid1.DataSource = goView
        Page.DataBind()
        Dim iRow As Integer
        Dim iCol As Integer
        Dim iRows As Integer
        Dim iColumns As Integer
        Dim lcColText As String
        iRows = goView.Table.Rows.Count
        iColumns = goView.Table.Columns.Count

        'Loop through the rows and set colors
        For iRow = 1 To iRows - 1
            DataGrid1.CurrentPageIndex = iRow
            For iCol = 1 To iColumns - 1
                ' Update the individual cell for each Row
                ' If cell text =0 then green otherwise red
                lcColText = DataGrid1.Columns(iCol).ToString
                If Val(lcColText) = 0 Then
                    DataGrid1.Columns(iCol).ItemStyle.BackColor = Color.Green
                Else
                    DataGrid1.Columns(iCol).ItemStyle.BackColor = Color.Red
                End If
            Next
        Next
Thanks for any help.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform