tags:

views:

324

answers:

2

I have a gridview with this field:

<asp:TemplateField HeaderText="Title">      
 <ItemTemplate>
   <asp:Literal ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' />   
 </ItemTemplate>
</asp:TemplateField>

If the title is too long it completely breaks the gridview. How can I:

  1. Make the width of this column fixed.
  2. If the content is too long, break it into multi lines.
A: 

try setting the ItemStyle-Width

<asp:TemplateField HeaderText="Title" ItemStyle-Width="300px" ItemStyle-Wrap="true"></asp:TemplateField>

you may need to use styling to wrap as well.

YonahW
what is "styling to wrap"?Modifying only ItemStyle-Width doesn't work.
I added the wrapping to the definition as well. did the width affect anything at all?
YonahW
A: 

Using the server control properties:

<asp:TemplateField HeaderText="Title" 
                   ItemStyle-Width="300px"
                   HeaderStyle-Wrap="true"
                   ItemStyle-Wrap="true">
    <ItemTemplate>
       <asp:Literal ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' />   
    </ItemTemplate>
</asp:TemplateField>

These server control properties generate inline css styles. Personally, I would create appropriate css classes in your stylesheet and assign to the HeaderStyle-CssClass and ItemStyle-CssClass properties.

HectorMac