Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to set line break in gridview in asp.net with c#. I am having template column and in it if text for a field is large it should have line break while binding from the database.

What I have tried:

<cc1:XDataGrid ID="grdNONMOLSalary" runat="server" AllowCustomPaging="True" AllowPaging="True"
                  Width="100%" AutoGenerateColumns="False" CssClass="NeST_DATAGRID_FIXED_SIZE"
                  ShowFooter="True" OnItemCommand="grdNONMOLSalary_ItemCommand"
                  OnPageIndexChanged="grdNONMOLSalary_PageIndexChanged" OnPagerClicked="grdNONMOLSalary_PagerClicked">
                  <AlternatingItemStyle BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA2"></AlternatingItemStyle>
                  <ItemStyle BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA" HorizontalAlign="Left"></ItemStyle>
                  <HeaderStyle CssClass="NeST_DATAGRID_HEADING"></HeaderStyle>
                  <PagerStyle HorizontalAlign="Right" Mode="NumericPages" Wrap="True" CssClass="NeST_DATAGRID_CELLDATANEW" />
                  <Columns>
                      <asp:TemplateColumn HeaderText="Sl No." ItemStyle-HorizontalAlign="Center">
                          <ItemTemplate>
                              <%--    <asp:HiddenField ID="hidIsRepair" runat="server" Value='<%# Eval("IsRepair") %>' />--%>
                              <asp:Label ID="lblRecordID" runat="server" Text='<%# (grdNONMOLSalary.CurrentPageIndex *grdNONMOLSalary.PageSize) + Container.ItemIndex +1  %>' Style="position: static"></asp:Label>
                              <asp:HiddenField ID="hidID" runat="server" Value='<%#  (grdNONMOLSalary.CurrentPageIndex *grdNONMOLSalary.PageSize) + Container.ItemIndex +1 %>'></asp:HiddenField>

                          </ItemTemplate>
                          <HeaderStyle Width="5%"></HeaderStyle>
                      </asp:TemplateColumn>


                      <asp:TemplateColumn HeaderText="Employee ID">
                          <ItemTemplate>
                              <asp:Label ID="glblEmployeeID" runat="server" Text='<%# Eval("EmployeeID") %>'
                                  Style="position: static"></asp:Label>
                          </ItemTemplate>
                          <HeaderStyle Width="8%" />
                      </asp:TemplateColumn>
Posted
Updated 24-Apr-17 6:47am

1 solution

If you want to wrap text in bound column of gridview, check this: asp.net - how to wrap your text in the boundfield of Gridview - Stack Overflow[^]

Vaibhav wrote:


It is always recommended to specify widths for columns requiring text wrapping.

A similar question exists:
how to wrap text in boundfield column in gridview[^]

You may also try the following:

Gridview text not wrapping in IE8[^]

Hope it helps!
 
Share this answer
 
Comments
Karthik_Mahalingam 24-Apr-17 19:47pm    
5
Maciej Los 25-Apr-17 17:01pm    
Thank you, Karthik.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900