Adding CSS to the Grid Registry

3

I'm trying to add a bold to a record in the grid, but it appears as " <b>Nome</b> " and not " Name " as it should.

I'mdoingthisforcodebehind,throughLINQ

Here'smyViewUltimateShort()method:

privatevoidexibirUltimoSorteio(){varapostadores=(fromjin_contextEntities.TB_JOGOSjoinsin_contextEntities.TB_SORTEIOSonj.SORT_IDequalss.SORT_IDjoinain_contextEntities.TB_APOSTADORESonj.APO_IDequalsa.APO_IDselecta).Distinct().OrderBy(x=>x.APO_NOME).ToList();vartb_apostador=newList<TB_APOSTADORES>();tb_apostador.AddRange(apostadores.Select(apostador=>newTB_APOSTADORES{APO_NOME="<b>"+apostador.APO_NOME+"</b>"
    }));

    gvResultados.DataSource = tb_apostador;
    gvResultados.DataBind();
}
    
asked by anonymous 27.11.2014 / 18:24

2 answers

5

Event RowDataBound of your grid, you can use:

if (e.Row.RowType == DataControlRowType.DataRow)
{
  string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);
  e.Row.Cells[0].Text = decodedText;
}
    
27.11.2014 / 18:35
5

You can use this line to color your column (not counting the title):

gvResultados.Columns[0].ItemStyle.Font.Bold = true;

The interesting thing is that you can apply any style you want, just change the .ItemStyle.Font.Bold part to the formatting you need.

I also think you can use this for (which allows more control when changing styles, per row and column):

for (int i = 0; i < gvResultados.Rows.Count; i++)
{
    gvResultados.Rows[i].Cells[0].Font.Bold = true;
}

In this loop, the GridView is traversed by rows, so if you want to paint the cells of the first column, use Cells [0], if it is the second column, use Cells [1], and so on. / p>

Note: I'm not sure if the column headings (APO_NAME) count as Row, if you count, use i = 1     

27.11.2014 / 18:55