kailashnkute
kailashnkute

Reputation: 41

How to make row in gridview bold and regular programatically

Hi I have written program in c# outlook where u can send, receive, reply and forward the mails in text format through database I used gridview to retrieve the mails. But the new task is how to mark the unread message as bold and read message as regular in text.

help needed

Upvotes: 1

Views: 13751

Answers (4)

YPZ
YPZ

Reputation: 21

For an asp:GridView, wouldn't this be enough?

 yourGrid.DataSource = yourDataTable;
 yourGrid.DataBind();

 foreach (GridViewRow item in yourGrid.Rows)
 {
      if (isRead/Unread condition)
      {
          item.Cells[yourCell].Text = 
          "<b>" + item.Cells[yourCell].Text + "</b>";                   
      }
 }

Upvotes: 0

ihebiheb
ihebiheb

Reputation: 5183

I am using telerik radgriw for asp.net (I don't know if it also work on asp grids)

on the ItemDataBound (rowdatabound in asp grids)

protected void Dtg_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem row = (GridDataItem)e.Item;
    if (decimal.Parse(row["UniqueColumnName"].Text) > 0)
    {
        // iterate on cells
        for (int i = 0; i <= 6; i++)
            row.Cells[i].CssClass = "gridCellBoldRed";
    }
}

}

where gridCellBoldRed is a CSS calss (in my case its in ~/CSS/Style.css)

.gridCellBoldRed
{
    font-weight:bold;
    color: Red;
}

Upvotes: 0

Tarydon
Tarydon

Reputation: 5183

This may not be the direct answer to your question, but I think a better way to do this would be use a ListView. Then, you can use a DataTemplate for read items, and a different one for unread items. Then, just binding the set of mail items to this listview will cause the ListView to generate and display the UI for all the items. The main advantage of this will be that the UI will be virtualized, meaning UI items will be generated only as needed (when they scroll into view) and will be disposed automatically, keeping your UI responsive even when you have a huge number of items in the ListView.

You can then implement a DataTemplateSelector to pick between the two DataTemplates, based on some of the attributes of the mail items.

Upvotes: 0

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36627

You can loop through your rows by using.

DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(dataGridView.Font, FontStyle.Bold);
foreach(DataGridViewRow dg_r in myDataGridView.rows) 
{
  dg_r.DefaultCellStyle = style; // sets Row Style to Bold
}

Upvotes: 3

Related Questions