Reputation: 905
I can't make this GridView column change its width, I have tried this:
<asp:BoundField DataField="ABC" HeaderText="ABC" SortExpression="ABC" ControlStyle-Width="200%">
Or as pixels:
<asp:BoundField DataField="ABC" HeaderText="ABC" SortExpression="ABC" ControlStyle-Width="500px">
Or this inside the Boundfield tags:
<ItemStyle HorizontalAlign="Center" Width="500px"/>
Also tried this on code-behind:
Protected Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
e.Row.Cells(7).Width = 500
End Sub
How do I get it right?
Upvotes: 0
Views: 5539
Reputation: 5349
Here is how it can be done. I am re-sizing the columns who having property : Visible = True
Private Sub GridViewColumnsrResize(ByVal aspectratio As Integer, ByVal gv As DataGridView)
Try
Dim col_count As Integer = gv.Columns.Count
For j As Integer = 0 To col_count - 1
If gv.Columns(j).Visible = True Then
gv.Columns(j).Width = gv.Columns(j).Width * aspectratio
End If
Next
Catch ex As Exception
'output ex
End Try
End Sub
Upvotes: 4
Reputation: 905
I solved this issue by setting a fixed width for the GridView itself, it may not be for a specific column but it shares its width among all the GridView columns, thus expanding the column I wanted to expand.
<asp:GridView ID="GridView3" runat="server" DataSourceID="SqlDataSource4" AutoGenerateColumns="False" CssClass="Gridview" Width="800px">
Upvotes: 0
Reputation: 9862
Suggestion if you want the value to come in one line , for that you are increasing width then you can try this:
add a cssClass
to you Gridview
like cssClass=gridContainer
,
add in the .css
file:
.gridContainer
{
white-space:nowrap;
}
for more option, look white-space property
Upvotes: 0
Reputation: 867
I just posted this related thread yesterday with a similar issue. Short answer is you can't. There is a workaround as noted in this thread (at the bottom):
How can I print a full gridview area via a custom print window?
Upvotes: 0