views:

39

answers:

2

I am using a grid view in my asp.net application. In one column i need to display description(minimum 5 characters. Maximum 255 characters).i am using a label to hold description in that grid view.

But my problem is that if the description is larger it stretches in the browser and show it in one line. I want to display description in multi line (like a paragraph)

I hope some one help me . the entire grid view code is shown below

  <asp:GridView ID="gv_View_Documents" runat="server" AllowSorting="true" DataKeyNames="DocumentName,Description"  SkinID="customGridview" AutoGenerateColumns="false" OnSorting="gv_View_Documents_Sorting" OnRowCancelingEdit="gv_View_Documents_RowCancelingEdit"  OnRowCommand="gv_View_Documents_RowCommand"
                  OnRowEditing="gv_View_Documents_RowEditing" OnRowUpdating="gv_View_Documents_RowUpdating" >
                  <Columns>
                      <asp:TemplateField HeaderText="Document Name" HeaderStyle-Width="200"  HeaderStyle-CssClass="GridHeaderStyle" SortExpression="DocumentName" >
                           <ItemTemplate>
                                <asp:LinkButton CommandName="ViewDocument" CssClass="GridHeaderStyle" ID="hlnk_View_Document" runat="server" CommandArgument='<%# Bind("DocumentName") %>' Text='<%# Bind("DocumentName")  %>'>
                                </asp:LinkButton>
                            </ItemTemplate>
                         </asp:TemplateField>


                       <asp:TemplateField HeaderStyle-Width="200" HeaderText="Description">

                         <ItemTemplate>


                            <asp:Label  ID="lbl_gv_DocumentDescription" runat="server" Text='<%# Bind("Description") %>' ></asp:Label></ItemTemplate>

                            <EditItemTemplate>
                            <asp:TextBox ID="txt_gv_EditDescription" MaxLength="250" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                           </EditItemTemplate> 
                            </asp:TemplateField>

                            <asp:TemplateField HeaderStyle-Width="50" HeaderStyle-CssClass="GridHeaderStyle" ShowHeader="False"  >
                          <EditItemTemplate>
                            <asp:LinkButton ID="Bttn_Update_Description"  ForeColor=" #555555" runat="server" CausesValidation="False"
                                CommandName="Update" Text="Update"></asp:LinkButton>&nbsp;<asp:LinkButton ID="Bttn_Cancel_Settings" ForeColor=" #555555" runat="server" CausesValidation="False"
                                CommandName="Cancel" Text="Cancel"></asp:LinkButton></EditItemTemplate><ItemTemplate>
                            <asp:LinkButton ID="Bttn_Edit_Description"  ForeColor=" #555555" runat="server" CausesValidation="False" CommandName="Edit" 
                                Text="Edit" ></asp:LinkButton></ItemTemplate><ControlStyle CssClass="edit" />
                    </asp:TemplateField>


                   </Columns>
                  </asp:GridView>
A: 

You can set the ItemStyle of the TemplateField to true like this:

<ItemStyle Wrap="true" Width="100px" />

Complete gridview code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemStyle Wrap="true" Width="100px" />
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("Age") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Screenshot:

alt text

Lee Sy En
its not working :(
Shameer
strange. it works for me (see edit).
Lee Sy En
i tried this too . but not working for me. the original asp code is added in my EDITed question. :(. and i saw the screen shot.that is exactly i wanted
Shameer
A: 

Sometimes ItemStyle Wrap="true" doesn't work. To be certain your text wraps, surround the Label in a and set a width on the surrounding div.

EDIT

<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text="<%# Eval("ID") %>"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
        <ItemTemplate>
            <div style="width:100px;">
                <asp:Label ID="Label2" runat="server" Text="<%# Eval("Name") %>"></asp:Label>
            </div>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text="<%# Eval("Age") %>"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
TheGeekYouNeed
how can i place a div in inside a gridview . is it possible?
Shameer
look at my edited answer
TheGeekYouNeed
i tried this. but not working for me. the original asp code is added in my EDITed question
Shameer
TheGeekYouNeed