Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 26th, 2003, 05:23 PM
Authorized User
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Right align text in labels in a templatecolumn

In my datagrid, I have a template column, in which each cell has a checkbox and a label. I need to right align the text in the labels (actually they are numbers converted to string type). I tried left padding all the numbers to make them same string size, but they are sill left aligned. Any ideas?


Here is part of the code:

Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn

        Dim lblOrders As New Label()
        Dim cbOrders As New CheckBox()

        cbOrders.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
        AddHandler cbOrders.DataBinding, AddressOf ItemCheckTemplate_Databinding

        lblOrders.Font.Size = System.Web.UI.WebControls.FontUnit.XSmall
        AddHandler lblOrders.DataBinding, AddressOf ItemOrdersTemplate_Databinding

    End Sub

    Private Sub ItemOrdersTemplate_Databinding(ByVal sender As Object, ByVal e As EventArgs)

        Dim lblTemp As Label = CType(sender, Label)
        Dim Container As DataGridItem = CType(lblTemp.NamingContainer, DataGridItem)
        Dim txtTemp As String

        txtTemp = Convert.ToString(DataBinder.Eval((CType(Container, DataGridItem)).DataItem, sOrderCol))
        txtTemp = Space(6 - txtTemp.Length) & txtTemp
       lblTemp.Text = txtTemp

Old August 27th, 2003, 08:44 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Are you trying to make it look like this? (where X is the checkbox)
 X      1
 X     12
 X    123
 X   1234
 X  12345
 X 123456
 Obviously using right text align in the checkbox control only puts the text on the right versus the left, so that's why I am assuming you are trying to do something more complicated.

The only way I can figure you could do this is to break up the checkbox and it's label. Have a checkbox control with no label, then a label control by itself. Put each in a cell in a table inside the data grid cell and properly align the two cells to suit your needs. Set the table to be 100% width so all the cells align left and right against the inside edge of their parent data grid cell.
        <table width="100%" border="0"><tr>
            <td align="left">
                <asp:CheckBox Runat="server" ID="chkMyCheckBox" />
            <td align="right">
                <asp:Label Runat="server" ID="lblMyCheckBoxLabel" />

Similar Threads
Thread Thread Starter Forum Replies Last Post
text-align:justify; and <BR> anshul HTML Code Clinic 23 June 18th, 2018 03:04 AM
CSS Text Align webnitro CSS Cascading Style Sheets 3 December 8th, 2005 01:19 PM
Align text in textarea crmpicco HTML Code Clinic 27 June 14th, 2005 08:26 AM
Align IMG with text Snib HTML Code Clinic 12 April 8th, 2004 10:16 AM
Align text acko ASP.NET 1.x and 2.0 Application Design 2 January 9th, 2004 10:21 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.