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. Advertisements

  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, Nov 21, 2006
    1. Advertisements

  3. 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.


    End If

    End While


    dgSurveyResults.DataSource = dt_comments


    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


    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)


    End Try

    End Sub


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

    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,


    Paul Chalekian, Nov 21, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.