Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:24:10+00:00 2026-06-04T19:24:10+00:00

I have a gridview with autogenerated columns that I set programmatically I want to

  • 0

I have a gridview with autogenerated columns that I set programmatically I want to format the column width. This is my code for my gridview in code behind…

If Not Page.IsPostBack Then
    Dim budgetTable As New DataTable("Budgets")

    budgetTable.Columns.Add("Approval Date", GetType(Date))
    budgetTable.Columns.Add("Total Amount", GetType(String))
    budgetTable.Columns.Add("Comments", GetType(String))
    budgetTable.Columns.Add("Initials", GetType(String))

    Try
        For i As Integer = 0 To 0
            Dim tableRow As DataRow = budgetTable.NewRow()
            tableRow("Approval Date") = Date.Today
            tableRow("Total Amount") = ""
            tableRow("Comments") = ""
            tableRow("Initials") = ""
            budgetTable.Rows.Add (tableRow)
        Next
        Session("BudgetsTable") = budgetTable
        BindData()
    Catch ex As Exception

    End Try
End If

And this is the gridview on the html side:

<asp:GridView ID="gvOLIAdj" runat="server" CssClass="td8" CellPadding="4" ForeColor="#333333" PageSize="2" ViewStateMode="Enabled">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    <Columns>
        <asp:CommandField EditText="Add" ShowEditButton="True" />
    </Columns>

    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#E9E7E2" />
    <SortedAscendingHeaderStyle BackColor="#506C8C" />
    <SortedDescendingCellStyle BackColor="#FFFDF8" />
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:24:11+00:00Added an answer on June 4, 2026 at 7:24 pm

    — EDIT —

    (removed old contents after reading comments from OP, since that won’t help)

    Try using the RowDataBound event to set the widths (or any other properties).

    UNTESTED Code:

    Protected Sub gvOLIAdj_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvOLIAdj.RowDataBound
        If (e.Row.RowType = DataControlRowType.Header) Then
            e.Row.Cells(0).Width = 100  '100 pixels
            e.Row.Cells(1).Width = 50
            e.Row.Cells(2).Width = 200
            e.Row.Cells(3).Width = 150
        End If
    End Sub
    

    If the above doesn’t work, try setting it for e.Row.RowType = DataControlRowType.DataRow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that uses autogenerated columns, because the user can select the
I have created a gridview in code behind (as in its not physically present
I have a gridview with a column of asp buttons that I toggle the
I have a gridview in which a specific column Date . I have set
I have one GridView with 3 Column and 3 Rows I want to change
I have GridView and this grid has setup paging, but this paging not show
I am using gridView. I have 4 auto generated columns and 1 generated by
Have a gridview control which will show X amount of rows. I want to
I have a gridview with 13 pages with 5 item each. The first column
I am working on gridview and I am binding the data from code behind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.