Results 1 to 4 of 4

Thread: Center Text in a Label

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Center Text in a Label

    How can you center the text in a label inside a cell? I'm adding the label to the cell dynamically.
    VB Code:
    1. Dim lbl As New Label
    2.                 lbl.Style.Add("ALIGN", "center") 'these doesn't seem to work
    3.                 lbl.Font.Size = FontUnit.XXSmall
    4.                 lbl.Text = xImage.Attributes("title").Value & "<BR>"
    5.                 'I can do it by adding html in there but was looking for a better way
    6.                 'lbl.Text = "<P style=""TEXT-ALIGN: center"">" & xImage.Attributes("title").Value & "</P><BR>"
    7.  
    8.                 Dim hl As New HyperLink
    9.                 hl.NavigateUrl = xImage.Attributes("fullsize").Value
    10.                 hl.ImageUrl = xImage.Attributes("thumbnail").Value
    11.  
    12.                 tc = New TableCell
    13.                 tc.Controls.Add(lbl)
    14.                 tc.Controls.Add(hl)
    15.                 tr.Cells.Add(tc)
    Also how can I get the Hyperlink to go down a line? Right now I just add a <BR> in there but is there another way?

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You could use a literal control and set its text property to the html you want to display and add it to the cell...Of course, you are still dealing with html.

    Also, the br tag is it as far as I know.

  3. #3

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    That is what I ended up doing is using a literal control but I was hoping that there was a style I could use. Oh well thanks for the advice.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Try This:
    lbl.Style.Add("text-align","center")

    As for the <BR>, that is the proper way to do it.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width