Pregunta

Estoy tratando de cambiar el color de fila de un control de datos ...

        <asp:DataList ID="dlTrades" Width="100%" 
            RepeatDirection="Horizontal" 
            RepeatColumns="6" runat="server" 
            DataSourceID="objTrds" 
            OnItemDataBound="dlTrades_ItemDataBound">
            <ItemTemplate>
             <table>
                   <tr>
                    <td>
                      <b>
                      <%# DataBinder.Eval((System.Data.DataRowView)Container.DataItem, "Status") %>
                      </b>
                    </td>
                   </tr>
                 </table>
                 <table>
                   <tr>
                      <td><%# DataBinder.Eval((System.Data.DataRowView)Container.DataItem, "Hold") %>
                      </td>
                   </tr> 
                 </table>
            </ItemTemplate>
        </asp:DataList>

Con el siguiente evento de itemdatabound:

protected void dlTrades_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        System.Data.DataRowView drv = (System.Data.DataRowView)(e.Item.DataItem);

        string hld = (string)drv.Row["Hold"].ToString();

        if (hld == "Trade")
        {
            e.Item.BackColor = System.Drawing.Color.LightGreen;
            e.Item.ForeColor = System.Drawing.Color.White;
            e.Item.Font.Bold = true;
        }

        if (hld == "Hold")
        {
            e.Item.BackColor = System.Drawing.Color.LightGray;
            e.Item.ForeColor = System.Drawing.Color.White;
            e.Item.Font.Bold = true;
        }

        System.Data.DataRowView drv2 = (System.Data.DataRowView)(e.Item.DataItem);

        string stat = (string)drv2.Row["Status"].ToString();

        if (stat == "Open")
        {
            e.Item.BackColor = System.Drawing.Color.LightGreen;
            e.Item.ForeColor = System.Drawing.Color.White;
            e.Item.Font.Bold = true;
        }
        if (stat == "Filled")
        {
            e.Item.BackColor = System.Drawing.Color.Gold;
            e.Item.ForeColor = System.Drawing.Color.White;
            e.Item.Font.Bold = true;
        }

        if (stat == "Closed")
        {
            e.Item.BackColor = System.Drawing.Color.IndianRed;
            e.Item.ForeColor = System.Drawing.Color.White;
            e.Item.Font.Bold = true;
        }

    }
}

El problema es que sea cual sea el último conjunto de colores de fondo ambas filas. ¿Cómo puedo separar las filas para que una fila sea el color de 'estado' y una fila es el color 'retener'?

Intenté usar etiquetas Div como una publicación anterior mencionada pero divid.Attributes.Add (Estilo establecido: color) no compiló ...

Gracias,

¿Fue útil?

Solución

Usar un control de etiqueta y expandirlo, el 100% del ancho de la columna funciona bien para esto.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top