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...
Printable View
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...
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:
<%@ Import Namespace = "System.Data.SqlClient" %> <%@ Import Namespace = "System.Data" %> <script language="vb" runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack bindGrid() End If End Sub Sub bindGrid() Dim connString As String = "user id=sa;password=sa;database=pubs;server=DeathAngel;" Dim cn As New SqlConnection(connString) Dim cmd As New SqlCommand("Select au_fname, au_lname From Authors",cn) cmd.Connection.Open() gridAuthors.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) gridAuthors.DataBind() End Sub </script> <html> <head> <title></title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:DataGrid id="gridAuthors" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn ItemStyle-Width="200px" HeaderText="FirstName" DataField="au_fname"/> <asp:BoundColumn ItemStyle-Width="100px" HeaderText="LastName" DataField="au_lname"/> </Columns> </asp:DataGrid> </form> </body> </html>