Vikas Kunte Vikas Kunte - 9 months ago 90
ASP.NET (C#) Question

set column width of a gridview in

I dragged and dropped a GridView from toolbox to Aspx page.the design code looks like this

<asp:GridView ID="gridview1" runat="server" style="text-align:center;width: 1327px;"
CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True"
EnableSortingAndPagingCallbacks="True" PageSize="50" AutoGenerateEditButton="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
Height="12px" VerticalAlign="Bottom" Width="12px" Wrap="False" />
<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" />

I have a column by name Address in database.The table is bound to this grid view using following VB.NET code

Dim ds as Data.DataSet
Dim da As New OleDbDataAdapter("select col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,Address from table, con)
gridviewrealestate.DataSource = ds

Now,When the gridview is displayed,the columns are very close to each other due to large information present in Address Column.I want to set the Address Column to a particular width.
Please help me how to do this.

Answer Source

You cannot (easily) change the size of a grid view's columns if the GridView is automatically generating the columns for you. You will have to create the columns yourself but this will let you control the layout of the columns as well as many other aspects of them as well. Creating custom columns in gridview