ASP.NET - unread message as bold and read message as regular in text in gridview

Asked By sri on 26-Jun-12 08:04 AM
Hi To All,

unread message as bold and read message as regular in text in gridview
how to do it.
Chintan Vaghela replied to sri on 26-Jun-12 08:09 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

 

 

 

Jitendra Faye replied to sri on 26-Jun-12 08:16 AM
For this implement code like this-

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        Label lblRead = (Label)e.Row.FindControl("lblRead");
        Label lblMessage = (Label)e.Row.FindControl("lblMessage");
        if (lblRead.Text == "true")
        {
          lblMessage.Font.Bold = true;
        }
        else
        {
          lblMessage.Font.Bold = false;
        }

     }
    }

TYy this and let me know.