Question Nested Gridview unable to set colours to rows for Parent Gridview base on data.


New member
Mar 31, 2014
Programming Experience
Hi All,

I am trying to set the rows colours in the parent grid view base on the data. For example in the coding, if the currency is USD then set the row to chocolate colour but instead my coding shows that its all in red even though there is currency USD data in the gridview. :confused::confused:

However it does not seems to be able to be working correctly, heres my code behind,

Protected Sub gvUserInfo_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound        e.Row.Cells(1).Visible = False

        Dim currency As String = e.Row.Cells(3).Text

        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("HedgingTestConnectionString").ConnectionString)

        If (e.Row.RowType = DataControlRowType.DataRow) Then

            For Each cell As TableCell In e.Row.Cells
                If currency = "USD" Then
                    cell.ForeColor = Color.Chocolate
                    cell.BackColor = Color.Red
                    Label1.Text = e.Row.Cells(3).Text
                End If

            Dim gv As GridView = DirectCast(e.Row.FindControl("gvChildGrid"), GridView)
            Dim ref As Integer = Convert.ToInt32(e.Row.Cells(1).Text)
            Dim cmd As New SqlCommand("select * from TT where Reference_NO=" & ref, con)
            Dim da As New SqlDataAdapter(cmd)
            Dim ds As New DataSet()

            gv.DataSource = ds

        End If
    End Sub

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Hedging_ID,CCY"        HeaderStyle-Font-Size="Medium" HeaderStyle-BackColor="SeaGreen" OnRowDataBound="gvUserInfo_RowDataBound" width="100%"  
        HorizontalAlign="Center" RowStyle-HorizontalAlign="Center" GridLines="None">
            <asp:TemplateField ItemStyle-Width="20px">
            <a href="JavaScript:divexpandcollapse('div<%# Eval("ref_ID")%>');">
            <img id="imgdiv<%# Eval("Hedging_ID")%>" border="0" src="plus.png" />
            <ItemStyle Width="20px"></ItemStyle>

            <asp:BoundField DataField="ref_ID" HeaderText="ID" SortExpression="ref_ID" />
            <asp:BoundField DataField="Bank_Name" HeaderText="Bank" SortExpression="Bank_Name" />
            <asp:BoundField DataField="CCY" HeaderText="Currency" SortExpression="CCY" />
            <asp:BoundField DataField="Ref_Date" DataFormatString="{0:d}" HeaderText="Contract Date" SortExpression="Ref_Date" />
            <asp:BoundField DataField="Ref_End_Date" DataFormatString="{0:d}" HeaderText="Maturity Date" SortExpression="Ref_End_Date" />
            <td colspan="100%">
            <div id="div<%# Eval("Hedging_ID")%>" style="display: none; position: relative; left: 15px; overflow: auto">
            <asp:GridView ID="gvChildGrid" runat="server" AutoGenerateColumns="false" BorderStyle="Double"  BorderColor="#df5015" GridLines="None" Width="700px" HorizontalAlign="Center">
            <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
            <RowStyle BackColor="#E1E1E1" HorizontalAlign="Center" />
            <AlternatingRowStyle BackColor="White" />
            <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
                    <asp:BoundField DataField="Invoice_Number" HeaderText="Invoice Number" SortExpression="Invoice_Number" />
                    <asp:BoundField DataField="Payment_Date" DataFormatString="{0:d}" HeaderText="Payment Date" SortExpression="Payment_Date" />
                    <asp:BoundField DataField="Payment_Amount" DataFormatString="{0:c2}" HeaderText="Payment Amount" SortExpression="Payment_Amount" />

<HeaderStyle BackColor="SeaGreen" Font-Size="Medium"></HeaderStyle>

<RowStyle HorizontalAlign="Center"></RowStyle>
Top Bottom