Representar un control en un contexto RowDataBound para insertarlo directamente en la celda

I am creating an unordered list object based on the information queried from the database.

protected virtual void grdProject_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        BulletedList shipsUL = new BulletedList();
        string[] shipIds = e.Row.Cells[4].Text.Split(',');

        foreach (string ship in shipIds)
        {
            shipsUL.Items.Add(ship.Trim());
        }
    }
}

Once I have created my UL object I want to set the contents of the cell (e.Row.Cells[4]) to the actual list object itself. I have tried an approach with shipsUL.RenderControl but I am confused by the need for HTMLWriters etc.. I come from a PHP background and this concept is strange to me.

Gracias.

preguntado el 02 de febrero de 12 a las 10:02

1 Respuestas

I managed to fix this by simply adding the bulletedlist control to the cells child controls:

...
foreach (string ship in shipIds)
        {
            shipsUL.Items.Add(ship.Trim());
        }

e.Row.Cells[4].Controls.Add(shipsUL);
...

This seems to replace the original text in the cell which was as I wanted anyway.

Respondido 02 Feb 12, 14:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.