Set fonts for grid dynamically

Discussion in 'ASP .Net Datagrid Control' started by Eagle, May 18, 2005.

  1. Eagle

    Eagle Guest

    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>
     
    Eagle, May 18, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:OjGgjW%...
    > 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>
    >
    >
     
    Ken Cox [Microsoft MVP], May 19, 2005
    #2
    1. Advertising

  3. Eagle

    Eagle Guest

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

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:%23WIT15$...
    > 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" <> wrote in message
    > news:OjGgjW%...
    > > 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>
    > >
    > >

    >
    >
     
    Eagle, May 19, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Girish
    Replies:
    4
    Views:
    672
    Patrick.O.Ige
    Jul 19, 2005
  2. =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=

    How to transfer a value from an Invisible Grid to an visible Grid

    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    472
    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=
    Oct 17, 2005
  3. Danny Tuppeny

    Grouped grid? Or grid within datalist?

    Danny Tuppeny, Oct 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    502
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Oct 27, 2005
  4. eagle

    Dynamically set the width of the grid by percentage

    eagle, Dec 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    114
    eagle
    Dec 1, 2005
  5. sam
    Replies:
    0
    Views:
    415
Loading...

Share This Page