vb asp gridview and select

Soldato
Joined
8 Mar 2005
Posts
3,859
Location
London, UK
Hmm;
I thought this would be simple but nahh.

Gridview is populated from a sqldatasource and I'm just trying to format the row/cell based on cell value containing part of a string. e.g. "VM" cell contains "123AAA321".

Code:
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.SelectedIndexChanged
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim view As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
            Select Case True
                Case (Convert.ToString(view("VM"))).Contains("AAA")
                    e.Row.BackColor = System.Drawing.Color.Green
                    Exit Select
                Case (Convert.ToString(view("VM"))).Contains("BBB")
                    e.Row.BackColor = System.Drawing.Color.Orange
                    Exit Select
                Case (Convert.ToString(view("VM"))).Contains("CCC")
                    e.Row.BackColor = System.Drawing.Color.Red
                    Exit Select
            End Select
        End If
    End Sub

I've tried various combinations of code but nothing doing! any pointers most welcome!
 
Code:
            if (e.Row.RowType == DataControlRowType.DataRow && !((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit))
            {
                DataRowView d = (DataRowView)e.Row.DataItem;

                if (d["StockHighlight"].ToString() == "Yes")
                {
                    e.Row.BackColor = System.Drawing.Color.Yellow;
                }

                if (d["ForecastHighlight"].ToString() == "Yes")
                {
                    e.Row.BackColor = System.Drawing.Color.Tomato;
                }
                }
            }

C# rather than VB but that's a snippet from where I do something similar.

What actual error if any are you getting?
 
Ew VB :(

What happens when stepping through?

I know I know! One day I will convert to c#!
Code:
            if (e.Row.RowType == DataControlRowType.DataRow && !((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit))
            {
                DataRowView d = (DataRowView)e.Row.DataItem;

                if (d["StockHighlight"].ToString() == "Yes")
                {
                    e.Row.BackColor = System.Drawing.Color.Yellow;
                }

                if (d["ForecastHighlight"].ToString() == "Yes")
                {
                    e.Row.BackColor = System.Drawing.Color.Tomato;
                }
                }
            }

C# rather than VB but that's a snippet from where I do something similar.

What actual error if any are you getting?
None; and after converting back to if and back to case select.

I clocked the issue:
Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
 
Back
Top Bottom