I have a GridView which uses BoundField for columns. I am trying to set a maxwidth for my UserInfo
column.
I have tried many many ways but non of them work. Below is the code for my GridView :
<asp:GridView ID="GridView1" AutoGenerateEditButton="True"
ondatabound="gv_DataBound" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="UserId"
DataField="UserId"
SortExpression="UserId"></asp:BoundField>
<asp:BoundField HeaderText="Username"
DataField="Username"
SortExpression="Username"></asp:BoundField>
<asp:BoundField HeaderText="UserInfo"
DataField="UserInfo"
SortExpression="UserInfo"></asp:BoundField>
</Columns>
</asp:GridView>
Looking for suggestions on how I can set the width of a specific column, which is my UserInfo
column.
Best Answer
I did a small demo for you. Demonstrating how to display long text.
In this example there is a column Name which may contain very long text. The boundField will display all content in a table cell and therefore the cell will expand as needed (because of the content)
The TemplateField will also be rendered as a cell BUT it contains a div which limits the width of any contet to eg 40px. So this column will have some kind of max-width!
Here is my demo codeBehind