How do I set Datagrid column widths (ASP Vb.Net)?

Discussion in 'ASP .Net' started by Jonathan, Feb 18, 2008.

  1. Jonathan

    Jonathan Guest

    I am new to Datagrids and asp.net (VB).

    In the sample code below, how do I set the Datagrid widths of the 4 columns
    I have from the query I have in the in the Access database?

    </head>

    <%@ Page language="VB" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <script language="VB" runat="server">

    Sub Page_Load(Sender as Object, E as EventArgs)

    Dim oConn As OleDbConnection
    Dim oComm As OleDbDataAdapter
    Dim sConn As String
    Dim sComm As String
    Dim oDataSet As New DataSet

    'Build the connection string
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"
    sConn += "Persist Security Info=False"

    'Build the SQL string
    sComm = "SELECT qryDataGrid01.* "
    sComm += "FROM qryDataGrid01;"

    'Create the connection and command objects
    oConn = New OleDbConnection(sConn)
    oComm = New OleDbDataAdapter(sComm, oConn)

    'Fill the dataset with the results of the query
    oComm.Fill(oDataSet, "qryDataGrid01")

    'Set the grid source to the dataset and bind the data
    oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
    oGrid.DataBind()

    End Sub
    </script>


    <asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
    HorizontalAlign="Left">
    <HeaderStyle Font-Bold="True"/>
    <AlternatingItemStyle BackColor="White" />
    </asp:datagrid>
    Jonathan, Feb 18, 2008
    #1
    1. Advertising

  2. Jonathan

    David Wier Guest

    Check out this tip from ASPNet101.com:
    http://www.aspnet101.com/aspnet101/tips.aspx?id=36

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "Jonathan" <> wrote in message news:fpbm4d$sjr$...
    >I am new to Datagrids and asp.net (VB).
    >
    > In the sample code below, how do I set the Datagrid widths of the 4
    > columns
    > I have from the query I have in the in the Access database?
    >
    > </head>
    >
    > <%@ Page language="VB" Debug="true" %>
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > <script language="VB" runat="server">
    >
    > Sub Page_Load(Sender as Object, E as EventArgs)
    >
    > Dim oConn As OleDbConnection
    > Dim oComm As OleDbDataAdapter
    > Dim sConn As String
    > Dim sComm As String
    > Dim oDataSet As New DataSet
    >
    > 'Build the connection string
    > sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    > sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"
    > sConn += "Persist Security Info=False"
    >
    > 'Build the SQL string
    > sComm = "SELECT qryDataGrid01.* "
    > sComm += "FROM qryDataGrid01;"
    >
    > 'Create the connection and command objects
    > oConn = New OleDbConnection(sConn)
    > oComm = New OleDbDataAdapter(sComm, oConn)
    >
    > 'Fill the dataset with the results of the query
    > oComm.Fill(oDataSet, "qryDataGrid01")
    >
    > 'Set the grid source to the dataset and bind the data
    > oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
    > oGrid.DataBind()
    >
    > End Sub
    > </script>
    >
    >
    > <asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
    > HorizontalAlign="Left">
    > <HeaderStyle Font-Bold="True"/>
    > <AlternatingItemStyle BackColor="White" />
    > </asp:datagrid>
    >
    >
    David Wier, Feb 18, 2008
    #2
    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. wh1974
    Replies:
    1
    Views:
    1,574
    =?Utf-8?B?RmVybmFuZG8gSHVudGg=?=
    Jan 11, 2005
  2. =?Utf-8?B?RWxtZXI=?=

    Datagrid column widths in edit mode

    =?Utf-8?B?RWxtZXI=?=, Apr 8, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,427
    =?Utf-8?B?RWxtZXI=?=
    Apr 19, 2005
  3. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Forced Column Widths in a DataGrid?

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 16, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,679
    Walter Wang [MSFT]
    Jun 20, 2006
  4. vpravin
    Replies:
    5
    Views:
    426
  5. Martin Gregorie

    How can I set column widths in a JTable

    Martin Gregorie, Oct 25, 2010, in forum: Java
    Replies:
    7
    Views:
    1,636
    Martin Gregorie
    Oct 27, 2010
Loading...

Share This Page