Results 1 to 2 of 2

Thread: sizing columns

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    sizing columns

    How do you size the columns in a datagrid? Seems like it should be something simple, like in the properties, but I don't see anything there...

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Use the ItemStyle-Width attribute. I don't use visual studio to write my html so i don't know if there's a datagrid property sheet somewhere in vs.net where you can set it(I looked but couldn't find one that would let you size an individual column).
    VB Code:
    1. <%@ Import Namespace = "System.Data.SqlClient" %>
    2. <%@ Import Namespace = "System.Data" %>
    3. <script language="vb" runat="server">
    4. Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    5.     If Not Page.IsPostBack
    6.         bindGrid()
    7.     End If
    8. End Sub
    9.  
    10. Sub bindGrid()
    11.     Dim connString As String = "user id=sa;password=sa;database=pubs;server=DeathAngel;"
    12.     Dim cn As New SqlConnection(connString)
    13.     Dim cmd As New SqlCommand("Select au_fname, au_lname From Authors",cn)
    14.     cmd.Connection.Open()
    15.     gridAuthors.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    16.     gridAuthors.DataBind() 
    17. End Sub
    18.  
    19. </script>
    20. <html>
    21.   <head>
    22.     <title></title>
    23. </head>
    24.   <body>
    25.     <form id="Form1" method="post" runat="server">
    26.         <asp:DataGrid  
    27.             id="gridAuthors"
    28.             runat="server"
    29.             AutoGenerateColumns="False">
    30.             <Columns>
    31.                 <asp:BoundColumn
    32.                     ItemStyle-Width="200px"
    33.                     HeaderText="FirstName"
    34.                     DataField="au_fname"/>
    35.                 <asp:BoundColumn
    36.                     ItemStyle-Width="100px"
    37.                     HeaderText="LastName"
    38.                     DataField="au_lname"/>
    39.             </Columns> 
    40.         </asp:DataGrid>    
    41.     </form>
    42.   </body>
    43. </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width