I have a table, in the table there are couple of buttons and a Gridview. I am trying to wrap the text in one of the boundfield of the Gridview.
I have tried to set the RowStyle Wrap="true" in the Gridview properties and set the ItemStyle Wrap="true" and the Width in the boundfield properties, but didn't work.
Following is my aspx.
<table align="center" border="0" cellpadding="0" cellspacing="2" >
<tr>
<td></td>
<td align="right">
<asp:Button ID="btnAdd" runat="server" Text="Add Subscription"
onclick="btnAdd_Click" CausesValidation="False" />
</td>
</tr>
<tr>
<td colspan="2">
<p align="center" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px" >
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</p>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="SubscriptionID,UserID"
DataSourceID="SqlDSEmailSubscriptions" Width="90%" CellPadding="4"
EnableViewState="False" AllowPaging="True">
<Columns>
<asp:TemplateField HeaderText="SubscriptionName" SortExpression="SubscriptionName">
<ItemTemplate>
<asp:LinkButton ID="lbtnSubscription" runat="server" CausesValidation="false"
Text='<%# Eval("SubscriptionName")%>' OnClick="lbtnSubscription_Click">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SubscriptionName" HeaderText="SubscriptionName"
SortExpression="SubscriptionName" Visible="false" />
<asp:BoundField DataField="SubscriptionID" HeaderText="SubscriptionID"
ReadOnly="True" SortExpression="SubscriptionID" />
<asp:BoundField DataField="ProductList" HeaderText="ProductList"
SortExpression="ProductList" />
<asp:BoundField DataField="DivisionList" HeaderText="DivisionList"
SortExpression="DivisionList" />
<asp:BoundField DataField="DisciplineList" HeaderText="DisciplineList"
SortExpression="DisciplineList" />
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"
SortExpression="UserID" Visible="false" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDSEmailSubscriptions" runat="server"
ConnectionString="<%$ ConnectionStrings:SPRConnectionString %>"
SelectCommand="SELECT [SubscriptionID], [SubscriptionName], [ProductList], [DivisionList], [DisciplineList], [UserID] FROM [sprEmailSubscriptions] WHERE ([UserID] = @UserID) ORDER BY [SubscriptionName]">
<SelectParameters>
<asp:SessionParameter Name="UserID" SessionField="userID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
Yes, you can parse it by every "x" caracters, but maybe it is better solution to put into header of columns to be fixed size and define wrap "true".
by that option you'll get same gridview size every time and better and more clearly user interface.
Use code: