?
Solved

changing font size within datagrid cell

Posted on 2005-04-26
3
Medium Priority
?
1,497 Views
Last Modified: 2013-12-03
Hello experts, i am using a webform with a datagrid.  Within the itemdatabound event of my datagrid i am trying to change the font size of text, within the datagrid cells.  I cant remeber how to change the font size below is what i tried.

     Private Sub dgactive_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgactive.ItemDataBound
        'handles the datagrid load
             If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
       ' if some condition is met set the text of the cell
                e.Item.Cells(2).Text = "Active"
                e.Item.Cells(2).Font = New Font("Arial", 14)

                e.Item.Cells(2).ForeColor = Color.Green
        '    Else
                e.Item.Cells(2).Text = "Not Active"
                e.Item.Cells(2).ForeColor = Color.Red
        '    End If
        End If
    End Sub
0
Comment
Question by:tentavarious
  • 2
3 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 13868991
As Font will be in ReadOnly Property New Font will not work.. Try Like following:

Private Sub dgactive_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgactive.ItemDataBound
        'handles the datagrid load
             If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
       ' if some condition is met set the text of the cell
                e.Item.Cells(2).Text = "Active"
                e.Item.Cells(2).Font.Name = "Arial"
                e.Item.Cells(2).Font.Size = 14

                e.Item.Cells(2).ForeColor = Color.Green
        '    Else
                e.Item.Cells(2).Text = "Not Active"
                e.Item.Cells(2).ForeColor = Color.Red
        '    End If
        End If
    End Sub

-tushar
0
 

Author Comment

by:tentavarious
ID: 13869119
Nope that doesnt work i get syntax errors "value type integer cannot be converted to System.Web.UI.Webcontrols.FontUnit
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 500 total points
ID: 13869136
Replace:
    e.Item.Cells(2).Font.Size = 14
With:
     e.Item.Cells(2).Font.Size = FontUnit.Point(14)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question