Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: How to re-flow GridView cells over multiple lines

I have an application which contains a table with two columns: messageid and messageDesc . Inside the messageDesc column there is a message description. When I try to bind the GridView to the messageDesc column, it renders the entire column on a single line, requiring the user to scroll horizontally to view the complete text. I want to prevent this by having the description flow over multiple lines. How do I do this?

I have tried using the ItemStyle attribute but it's not working. Please suggest a solution. In addition to this, I can't change the database message content.

Thanks in advance.

like image 689
user1379430 Avatar asked Dec 05 '25 15:12

user1379430


2 Answers

Warp label insdie div element and than try out this will surely work for you

 <asp:TemplateField> 
        <ItemTemplate>
             <div style="width:100px;">
                 <asp:Label ID="Label2" runat="server" Text="<%# Eval("description") %>"></asp:Label>
             </div>
         </ItemTemplate>
     </asp:TemplateField> 

or

<ItemStyle Wrap="true" Width="100px" /> 
like image 188
Pranay Rana Avatar answered Dec 11 '25 02:12

Pranay Rana


You can display data in textbox using template field instead of bound field. See below, textbox code. Your TemplateField would look like this:

<asp:TemplateField>
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" Text='<%# Eval("MessageDesc") %>'
            TextMode="MultiLine"></asp:TextBox>
    </ItemTemplate>
</asp:TemplateField>

The ReadOnly setting keeps users from editing the data while having it still enabled for them. In Edit mode, of course you would set ReadOnly to false.

like image 43
Sai Kalyan Kumar Akshinthala Avatar answered Dec 11 '25 02:12

Sai Kalyan Kumar Akshinthala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!