Hi,

I'm using a dataTable to bind my gridView and during the data binding I need to make some cells bold. The structure I'm looking for is this:

Person
contact
Person 2
contact

To include the spaces when binding the table I'm using Server.HtmlDecode("&nbsp;&nbsp;&nbsp;"). I tried Server.HtmlDecode("<b>") ... Server.HtmlDecode("</b>") to make the text bold, but it didn't work.

Any suggestions?

Thanks,

Ana

Recommended Answers

Put them in a <div> or <span> and set the class or in line style?

<div style="font-weight: bold"> text </div>

and use the same method to get the indent

<div style="text-indent:10px"> text </div>

or use padding.

Jump to Post

You can try like this.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[2].Font.Bold = true;    
        }

    }
Jump to Post

All 5 Replies

Put them in a <div> or <span> and set the class or in line style?

<div style="font-weight: bold"> text </div>

and use the same method to get the indent

<div style="text-indent:10px"> text </div>

or use padding.

Put them in a <div> or <span> and set the class or in line style?

<div style="font-weight: bold"> text </div>

and use the same method to get the indent

<div style="text-indent:10px"> text </div>

or use padding.

This will not working in my case, because of the way I'm binding my gridView. First I'm binding it with all the "person" names and then I'm iterating through the "person" names and including the contacts associated. So, in the ASP.NET gridView I have:

<asp:Label ID="PersonOrContactName" runat="server" Text='<%#Eval("Name") %>' />

This means the list of person or contact names is one single column in my DataTable, and this columns is called "Name". The thing is: I want the cell bold only when it's a person name; when it's a contact name, it should be regular.

Is it possible to do?

Try with ITEMDATBOUND event

You can set a style in any cellls using e.item

You can try like this.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[2].Font.Bold = true;    
        }

    }

The best way to edit the gridview is to write the code in its RowDataBound event

Example :

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int j = 0; j < e.Row.Cells.Count; j++)
        {

            e.Row.Cells[j].Style.Add("BORDER-BOTTOM", "#aaccee 1px solid");

            e.Row.Cells[j].Style.Add("BORDER-RIGHT", "#aaccee 1px solid");
            e.Row.Cells[j].Style.Add("padding-left", "5px");

        }
    }

I Hope this will help you

Regards,
Karan Salekar

Hi,

I'm using a dataTable to bind my gridView and during the data binding I need to make some cells bold. The structure I'm looking for is this:

Person
contact
Person 2
contact

To include the spaces when binding the table I'm using Server.HtmlDecode("&nbsp;&nbsp;&nbsp;"). I tried Server.HtmlDecode("<b>") ... Server.HtmlDecode("</b>") to make the text bold, but it didn't work.

Any suggestions?

Thanks,

Ana

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.