Avinash Chandra
Avinash Chandra

Reputation: 183

making the gridview row bold depening on the label control value

I have a label control that has the value

123| value9| value6|value9

Right below this label control, I have a gridview, I want to make that item of the gridview bold that has the linkbutton with 123 value in it

so for e.g

value9     Value1             Value3                   Value4

345   Tested Value             Equipment1               Equipment3
456   Testing              Equipment9                   Equipment9
123   Value9               Valu6                         value9
789   Value8               Value10                         value20

900 value5 value3 value34

all the value in value9 is a linkbutton. I want the whole line to be bold 123 Value9 Valu6 value9 when the label control has 123 in it and if the label control has 789 in it then I want the 789 Value8 Value10 value20 to be bold. any help will be appreciated.

Upvotes: 1

Views: 5464

Answers (4)

Paul
Paul

Reputation: 1

I'm trying this now and it simply doesn't work. I've tried it on RowDataBound and on the DataBound event. Nothing. In vb.net, the RowDataBound code:

    If e.Row.RowType = DataControlRowType.DataRow Then
        If e.Row.Cells(7).Text.Contains("Emdeon") Then
            e.Row.Font.Bold = True
        End If
    End If

The DataBound code:

    For Each gvRow As GridViewRow In gvFiles.Rows
        If gvRow.Cells(7).Text.Contains("Emdeon") Then
            gvRow.Font.Bold = True
        End If
    Next

I have put breaks on these lines so I know they're executing. They have no effect.

Update: found the solution. This works:

    If e.Row.RowType = DataControlRowType.DataRow Then
        If e.Row.Cells(7).Text.Contains("Emdeon") Then
            For Each cell In e.Row.Cells
                cell.font.bold = True
            Next
        End If
    End If

Upvotes: 0

Manusha
Manusha

Reputation: 355

Hi I know this is a old post but it helped me to get the idea to bold the row on rad gird. So, for any one who interested to bold the rad grid row wise you can use below code.

if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                if (item["row_name"].Text.ToString() == "condition")
                {
                    item.Font.Bold = true;  //bold
                }

            }

Upvotes: 0

EMre
EMre

Reputation: 53

You can set the row font to bold in RowDataBound event;

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    { 
        //Check if it is not header or footer row
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Check your condition here
            if(e.Row.Cells[0].Text.Equals("123"))
            {
                e.Row.Font.Bold = true; // This will make row bold
            }
        }
    }

Upvotes: 3

citronas
citronas

Reputation: 19365

Have a look at the RowDataBound event.

Use the GridViewRowEventArgs object, to get a reference to the current Row and set its Font.Bold to true

You also need to include your if-condition into the RowDataBound event. How you do that depends on your datasource:

if (e.Row.RowType == DataControlRowType.DataRow)
{
// use QuickWatch to see how you can get your desired information from e.Row.DataItem
}

I've once written an article about the RowDataBound event: http://www.tomot.de/en-us/article/7/asp.net/gridview-overview-of-different-ways-to-bind-data-to-columns

Upvotes: 1

Related Questions