Align table columns with gridview columns

Discussion in 'ASP .Net' started by Jacksm, Nov 21, 2006.

  1. Jacksm

    Jacksm Guest

    How can I align an asp:table columns with gridview columns (the
    widths)? I have tried setting table.column(0).width =
    gridview.column(0).width at page_load but it doesn't work.

    Thanks in advance
    Jacksm, Nov 21, 2006
    #1
    1. Advertising

  2. This is not possible since the ultimate control on column width is in the
    browser hands and your instructions are treated as recommendations. You have
    to merge the table and the gridview content into the same control.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Jacksm" <> wrote in message
    news:...
    > How can I align an asp:table columns with gridview columns (the
    > widths)? I have tried setting table.column(0).width =
    > gridview.column(0).width at page_load but it doesn't work.
    >
    > Thanks in advance
    >
    Eliyahu Goldin, Nov 21, 2006
    #2
    1. Advertising

  3. Re: Align table columns with gridview columns - Setting?

    I have a very similar problem. In using a datagrid, I can dynamically change
    the column formatting/justification in Debug. But when deployed to our
    Intranet server, this formatting goes away and reverts to the default (left
    justified). Is this a setting issue?

    Specifically, I need

    some text columns justified into the center and

    some $ amount columns justified to the right

    On a Button:

    Private Sub btnReport2_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnReport2.Click

    Dim ls_locn_id As String = ""

    Dim ls_make As String = ""

    Dim ls_Amt As String = ""

    ' //Define a DataRow

    Dim dr_comments As DataRow

    ' //Define the DataColumns.

    dt_comments.Columns.Add(New DataColumn("LOCN", GetType(String)))

    dt_comments.Columns.Add(New DataColumn("MAKE", GetType(String)))

    dt_comments.Columns.Add(New DataColumn("AMT", GetType(String)))

    dr_comments = dt_comments.NewRow()

    ls_locn_id = "Central"

    ls_make = "Right-justified"

    ls_Amt = "10.00"

    dr_comments(0) = ls_locn_id

    dr_comments(1) = ls_make

    dr_comments(2) = ls_Amt

    ' //Add the data to the row now.

    dt_comments.Rows.Add(dr_comments)

    End If

    End While

    objreader.Close()

    dgSurveyResults.DataSource = dt_comments

    dgSurveyResults.DataBind()

    btnReport1.Enabled = True

    End Sub



    After the button:

    Private Sub dgSurveyResults_ItemDataBound(ByVal sender As Object,

    ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

    Handles dgSurveyResults.ItemDataBound

    Try

    Dim item As DataGridItem = CType(e.Item, DataGridItem)

    Dim i As Integer = e.Item.ItemIndex

    With item

    ..Cells(0).HorizontalAlign = HorizontalAlign.Center

    ..Cells(1).HorizontalAlign = HorizontalAlign.Right

    ..Cells(2).HorizontalAlign = HorizontalAlign.Right

    End With

    Catch tex As Threading.ThreadAbortException

    Catch ex As Exception

    Response.Write(ex.Message & ex.StackTrace)

    Finally

    End Try

    End Sub



    Incidentally:

    No error is thrown but with diagnostics in place the innermost code is
    executing.

    The operating systems of both my development system and the host server
    are Windows 2000.

    Another (possible) clue is that

    the color of my development system shows Blue text, but

    the color of the server-based text is Purple.

    Great thanks in advance,

    Puzzled

    "Eliyahu Goldin" <> wrote in
    message news:u7c%23$...
    > This is not possible since the ultimate control on column width is in the
    > browser hands and your instructions are treated as recommendations. You

    have
    > to merge the table and the gridview content into the same control.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Jacksm" <> wrote in message
    > news:...
    > > How can I align an asp:table columns with gridview columns (the
    > > widths)? I have tried setting table.column(0).width =
    > > gridview.column(0).width at page_load but it doesn't work.
    > >
    > > Thanks in advance
    > >

    >
    >
    Paul Chalekian, Nov 21, 2006
    #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. Kay
    Replies:
    2
    Views:
    7,137
  2. Leonardo Gangemi
    Replies:
    0
    Views:
    304
    Leonardo Gangemi
    Apr 7, 2004
  3. tshad

    text-align vs align

    tshad, Jun 23, 2005, in forum: HTML
    Replies:
    1
    Views:
    1,244
    David Dorward
    Jun 23, 2005
  4. Paul Lautman

    left align within centre align

    Paul Lautman, Mar 3, 2006, in forum: HTML
    Replies:
    3
    Views:
    564
    Paul Lautman
    Mar 3, 2006
  5. Steve Richter
    Replies:
    1
    Views:
    884
    Mark Rae
    Jun 24, 2007
Loading...

Share This Page