ASP.NET - Gridview Records as Bold font - Asked By Krishna T on 26-Jun-12 08:22 AM

Earn up to 10 extra points for answering this tough question.
Hi,

I need to make One Column Records in the gridview as Bold. Can you give me solution?
[)ia6l0 iii replied to Krishna T on 26-Jun-12 09:23 AM
Style the cell in the column 1 with the RowDataBound Event of the gridview. 

See the following example, where the cell[0] in each row, which is column1, is set to appear Bold. 

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


Hope this helps.

Jitendra Faye replied to Krishna T on 26-Jun-12 09:34 AM
Use this code-

<asp:TemplateField  ItemStyle-Font-Bold ="true">
          <ItemTemplate>
            <asp:Label ID="lblID" runat="server" Text='<%# Eval("id") %>'></asp:Label>
          </ItemTemplate>
 </asp:TemplateField>
Vikram Singh Saini replied to Krishna T on 26-Jun-12 12:21 PM
If it is boundfiled and you want to make it's items bold you can write:

 <Columns>
          <asp:BoundField HeaderText="Adm. no" DataField="AdmNo" ItemStyle-Font-Bold="true" />

      . . . . . . . .

Ravi Maurya replied to Krishna T on 26-Jun-12 12:43 PM
If you want to make BoundField value as bold than you can simply make it as 

<asp:BoundField DataField="CategoryName" HeaderText="Categories" ItemStyle-Font-Bold="true"/>

Hope this might help you.
DL M replied to Krishna T on 26-Jun-12 12:56 PM
Use this code
---------------
protected void GridView1_DataBound(object sender, EventArgs e)
{
      GridView1.Rows[0].Style.Add(HtmlTextWriterStyle.FontWeight, "Bold");
}

If you need to make selectedrow bold,

<SelectedRowStyle ForeColor="White" Font-Bold="True"
       BackColor="#738A9C"></SelectedRowStyle>

If you need to make a particular row bold,

gridViewDeleg.Rows[3].Font.Bold = true;
Chintan Vaghela replied to Krishna T on 27-Jun-12 01:32 AM

Hi Frndz,

 

Functionality:  bold Gridview Row based on Condition

 

 

To achieve this task,

 

Added one hidden filed to  Item Template for store read/Unread value

 

<ItemTemplate>

          <asp:HiddenField ID="MilestoneID" runat="server" Value="'<%#Eval("FlagReadUnread") %>" />

          </ItemTemplate>

 

Now get this hidden filed value in rowdataound event and check this hidded field value

 

Added RowDatabound event and set row font bold as following way

 

 

 

Full Logic   :

 

 

protected void GrvMfDetails_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

      HiddenField hdf = (HiddenField)e.Row.FindControl("MilestoneID");

 

      if (hdf.Value == "read")

      {

      e.Row.Font.Bold = true;

      }

    }

 

}

 

 

 

Hope this helpful!

Thanks

Chintan Vaghela replied to Krishna T on 27-Jun-12 02:08 AM

Hi Frndz,

 

Functionality:  bold Gridview Column  based on Condition

 

 

To achieve this task,

 

Added one hidden filed to  Item Template for store read/Unread value

 

<asp:TemplateField HeaderText="Message">

          <ItemTemplate>

            <asp:HiddenField ID="hdfMessageStatus" runat="server" Value='<%# Eval("Status") %>' />

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

          </ItemTemplate>

        </asp:TemplateField>

 

 

Now get this hidden filed value in rowdataound event and check this hidded field value

 

Added RowDatabound event and set row font bold as following way

 

 

 

Full Logic   :

 

 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

      if (e.Row.RowType == DataControlRowType.DataRow)

      {

        HiddenField hdfMessageStatus = (HiddenField)e.Row.FindControl("hdfMessageStatus");

 

        Label lblMessage = (Label)e.Row.FindControl("lblMessage");

 

        if (hdfMessageStatus.Value == "read")

        {

          // Take Item Template then Find Control value and assign to Bold

          lblMessage.Font.Bold = true;

          // Take Bound Column then find Position of Bound filed value and set to Bold

          e.Row.Cells[5].Font.Bold = true;

        }

      }

} 

 

 

Hope this helpful!

Thanks

RAJASEKHAR RAJENDRAN replied to Krishna T on 28-Jun-12 02:58 AM
Hi Krishna,

You can achieve this by just setting the row style to bold in row bound data event as below.

protected void GridView1_DataBound(object sender, EventArgs e)
{
    GridView1.Rows[1].Style.Add(HtmlTextWriterStyle.FontWeight, "Bold");
}


Hope the above helps.

Thanks & Regards,
Rajasekhar.R
aneesa replied to Krishna T on 01-Oct-12 01:41 AM
<asp:BoundField DataField="ColumnName" HeaderText="Column1" ItemStyle-Font-Bold="true"/>