Set fonts for grid dynamically

E

Eagle

Okay, I know you can set up a grid in html (see code below), but I want to
be able to do it dynamically, can someone help with the syntax? I've tried:
dg.Font = "Microsoft Sans Serif"
dg.Font.Name="Microsoft Sans Serif"
dg.Font.Names="Microsoft Sans Serif"
dg.Font.Size="8pt"
dg.Font.Size.unit=??????

Can you tell me how to do all of the below in code behind? Thanks.

<asp:datagrid id=dg runat="server"
EnableViewState=True BorderStyle="Double" GridLines="Horizontal"
BorderWidth="3px" BorderColor="#ccbccc" BackColor="White" CellPadding="4"
AutoGenerateColumns="False">
<FooterStyle ForeColor="#ccbccc" BackColor="White">
</FooterStyle>

<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#339966">
</SelectedItemStyle>

<EditItemStyle ForeColor="Black" BackColor="Silver" CssClass="DDL">
</EditItemStyle>

<ItemStyle ForeColor="#333333" BackColor="White">
</ItemStyle>

<HeaderStyle Font-Underline="True" Font-Bold="True" Wrap="False"
ForeColor="White" BackColor="#cccccc">
</HeaderStyle>
 
K

Ken Cox [Microsoft MVP]

Hi ???

Here's some examples to get you going. Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


If Not IsPostBack Then
Dim dg As New DataGrid
dg.ID = "dg"
dg.EnableViewState = True
dg.BorderStyle = BorderStyle.Double
dg.GridLines = GridLines.Horizontal
dg.BorderWidth = Unit.Parse("3px",
System.Globalization.CultureInfo.InvariantCulture)
dg.BorderColor = Color.FromArgb(204, 188, 204)
dg.BackColor = Color.White
dg.ForeColor = Color.Black
dg.CellPadding = 4
dg.ItemStyle.ForeColor = Color.Black
dg.AutoGenerateColumns = True
dg.Font.Size = FontUnit.Point(12)
dg.Font.Underline = False
dg.FooterStyle.ForeColor = Color.FromArgb(204, 188, 204)
dg.FooterStyle.BackColor = Color.White
dg.HeaderStyle.Font.Underline = True
dg.HeaderStyle.Font.Bold = True
dg.HeaderStyle.Wrap = False
dg.ForeColor = Color.White
'.... and so on.

dg.DataSource = CreateDataSource()
dg.DataBind()
PlaceHolder1.Controls.Add(dg)

http://msdn.microsoft.com/library/d...fsystemwebuiwebcontrolsfontinfoclasstopic.asp
 
E

Eagle

How about how to set the Font Name?? Like Times New Roman or Microsoft Sans
Serif?

Ken Cox said:
Hi ???

Here's some examples to get you going. Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


If Not IsPostBack Then
Dim dg As New DataGrid
dg.ID = "dg"
dg.EnableViewState = True
dg.BorderStyle = BorderStyle.Double
dg.GridLines = GridLines.Horizontal
dg.BorderWidth = Unit.Parse("3px",
System.Globalization.CultureInfo.InvariantCulture)
dg.BorderColor = Color.FromArgb(204, 188, 204)
dg.BackColor = Color.White
dg.ForeColor = Color.Black
dg.CellPadding = 4
dg.ItemStyle.ForeColor = Color.Black
dg.AutoGenerateColumns = True
dg.Font.Size = FontUnit.Point(12)
dg.Font.Underline = False
dg.FooterStyle.ForeColor = Color.FromArgb(204, 188, 204)
dg.FooterStyle.BackColor = Color.White
dg.HeaderStyle.Font.Underline = True
dg.HeaderStyle.Font.Bold = True
dg.HeaderStyle.Wrap = False
dg.ForeColor = Color.White
'.... and so on.

dg.DataSource = CreateDataSource()
dg.DataBind()
PlaceHolder1.Controls.Add(dg)

http://msdn.microsoft.com/library/d...fsystemwebuiwebcontrolsfontinfoclasstopic.asp

Eagle said:
Okay, I know you can set up a grid in html (see code below), but I want to
be able to do it dynamically, can someone help with the syntax? I've
tried:
dg.Font = "Microsoft Sans Serif"
dg.Font.Name="Microsoft Sans Serif"
dg.Font.Names="Microsoft Sans Serif"
dg.Font.Size="8pt"
dg.Font.Size.unit=??????

Can you tell me how to do all of the below in code behind? Thanks.

<asp:datagrid id=dg runat="server"
EnableViewState=True BorderStyle="Double" GridLines="Horizontal"
BorderWidth="3px" BorderColor="#ccbccc" BackColor="White" CellPadding="4"
AutoGenerateColumns="False">
<FooterStyle ForeColor="#ccbccc" BackColor="White">
</FooterStyle>

<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#339966">
</SelectedItemStyle>

<EditItemStyle ForeColor="Black" BackColor="Silver" CssClass="DDL">
</EditItemStyle>

<ItemStyle ForeColor="#333333" BackColor="White">
</ItemStyle>

<HeaderStyle Font-Underline="True" Font-Bold="True" Wrap="False"
ForeColor="White" BackColor="#cccccc">
</HeaderStyle>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top