JavaScript - making the gridview row bold - Asked By Anjali agarwal on 24-May-11 05:09 PM

Hi All,
How is it possible to bold one row of the gridview and unbold another row. I have the ID's of both rows stored in a hidden variable.
The variable are lblId and lbltemID
I want to make the  lblItemId bolded and lblId unbolded.
is it possible? I really need help with this.
Peter Bromberg replied to Anjali agarwal on 24-May-11 08:43 PM
So is this an ASP.NET gridview? You posted in the JavaScript topic.  You can defiinitely do what you ask but first you need to be specific about what platform, what framework, and perhaps give sample code. 

When posting to forums, its "garbage in, garbage out". If you won't take the time to be specific, it will be very hard to get specific answers.
Ravi S replied to Anjali agarwal on 24-May-11 09:53 PM

You can loop through your rows by using.
DataGridViewCellStyle style = new DataGridViewCellStyle();
.Font = new Font(dataGridView.Font, FontStyle.Bold);
foreach(DataGridViewRow dg_r in myDataGridView.rows)
.DefaultCellStyle = style; // sets Row Style to Bold

 refer the link for examples

Nikhil Mahajan replied to Anjali agarwal on 24-May-11 10:23 PM
This will make the  row bold of gridview row no 3.

GridView1.Rows(GridView1.Rows.Count - 1).Cells(3).Font.Bold = True

and to unbold any row which was previously bold use below code

GridView1.Rows(GridView1.Rows.Count - 1).Cells(3).Font.Bold = false

TSN ... replied to Anjali agarwal on 24-May-11 11:24 PM

you have row databound event for gridview which helps in changing the layout  of the grid after binding the data to it...

here in the sample ifor which it will change the color of the row...

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = (DataRowView)e.Row.DataItem;
if (Convert.ToInt32(drv["YourColumn"]) == "youyr itemId")
//The current product has 0 items in stock
e.Row.Font.Bold = true; //Make the font bold
else if (Convert.ToInt32(drv["YourColumn"]) == "youyr anotheritemId")
//The current product has 0 items in stock
e.Row.Font.Bold = false; //Make the font bold

hope this helps you...
Riley K replied to Anjali agarwal on 24-May-11 11:41 PM
If you want alternate row to be bold use AlternateRowStyle attribute of gridview

 <asp:GridView ID="gridView1" runat="server" onrowdatabound="gridView1_RowDataBound">
  <AlternatingRowStyle Font-Bold="true" />

if you need to make a particular row bold,

gridViewDeleg.Rows[3].Font.Bold = true;

Anjali agarwal replied to Riley K on 25-May-11 05:15 PM
Unfortunately, none of the answers helped me. I think I need to be more descriptive about my questions.

  I am trying to make the gridview row bold, The first row of my gridview is linkbuttons. when someone clicks on the linkbutton then I want to make the row bold, this works fine in my code, I want to show a pop up message to the user if the user clicks on another link button. the pop up message should say "You are leaving the link (Old Link Button ID) and you are going to (new link button ID) here. Are you Sure? if the user clicks "Yes" in the pop up window then I need to bold the new link button row that the user just clicked otherwise if the user clicks "NO" or cancel then I need to keep the old link button row bolded.

I tried lot of things and put lot of hours in it, but couldn't get forward with this.  Below is my code

This is inside the DataBound event of grid: 
 foreach (GridDataItem item in RadGrid_IDPicker.Items) 
          if (Convert.ToString(DataBinder.Eval(item.DataItem, "IID")) == lblID.Text) 
            item.Style.Add(HtmlTextWriterStyle.FontWeight, "Bold"); 
if (lblIDTemp.Text != lblID.Text) 
   string radalertscript = "<script language='javascript'>function f(){confirm_select('" + lblIDtemp.ClientID + "'); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>"; 
              Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", radalertscript); 

In above code lblIDTemp is the value of the old link button which I stored in a hidden variable and lblID is the new link button value which i stored in another hidden varaible.

Any help will be higly apprecaited. I am trying to solve this problem since morning and don't know how to solve it.