This is a migrated thread and some comments may be shown as answers.

Question regarding No Wrap for Grid Cells

6 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ulrich
Top achievements
Rank 1
Ulrich asked on 04 Nov 2010, 10:37 AM
Hi all,

I have some problems regarding No Wrap for Grid Cells and I couldn't find any solution for this in the forum or the tutorials.

I have a grid with a HeaderTemplate and an ItemTemplate and I want to prevent the wrapping for cells content (see attached picture). The grid is filled dynamically, so where and how do I have to insert the NoWrap?

Any help would be appreciated!

Here's my code:

Private Sub Create_Templates(ByRef grdTemplate As RadGrid, ByVal sRegGruppe As String, ByVal nIdGruppe As Integer, ByVal bNurPlatzkosten As Boolean)
        Dim templateColumn As New GridTemplateColumn()
        templateColumn.HeaderText = sRegGruppe
        templateColumn.HeaderTemplate = New MyTemplateHeader(sRegGruppe, nIdGruppe, bNurPlatzkosten)
        templateColumn.ItemTemplate = New MyTemplate(nIdGruppe, bNurPlatzkosten)
  
        grdTemplate.MasterTableView.Columns.Add(templateColumn)
    End Sub
  
    Private Class MyTemplateHeader
        Implements ITemplate
        Private sColHeader As String
        Private nIdCol As Integer
        Private bNurPK As Boolean
        Sub New(ByVal sColHeaderBez As String, ByVal nIdGruppe As Integer, ByVal bNurPlatzk As Boolean)
            sColHeader = sColHeaderBez
            nIdCol = nIdGruppe
            bNurPK = bNurPlatzk
        End Sub
        Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
            Dim TmpTable As New Table()
            Dim TmpRow1 As New TableRow()
            Dim TmpRow2 As New TableRow()
            Dim cReg As New TableCell()
            Dim cES As New TableCell()
            Dim cDS As New TableCell()
            Dim cBU As New TableCell()
  
  
            TmpTable.Width = Unit.Percentage(100)
            cReg.Width = Unit.Percentage(100)
            cReg.Text = sColHeader
            cReg.HorizontalAlign = HorizontalAlign.Center
            TmpRow1.Cells.Add(cReg)
  
            cES.Text = "ES"
            cES.Width = Unit.Percentage(100)
            cES.HorizontalAlign = HorizontalAlign.Center
            TmpRow2.Cells.Add(cES)
  
            If bNurPK = False Then
                cReg.ColumnSpan = 3
                cDS.Text = "DS"
                cBU.Text = "Buchbar"
  
                cDS.Width = Unit.Percentage(45)
                cBU.Width = Unit.Percentage(10)
  
                cDS.HorizontalAlign = HorizontalAlign.Center
                cBU.HorizontalAlign = HorizontalAlign.Center
                TmpRow2.Cells.Add(cDS)
                TmpRow2.Cells.Add(cBU)
            End If
            TmpTable.Rows.Add(TmpRow1)
            TmpTable.Rows.Add(TmpRow2)
  
            container.Controls.Add(TmpTable)
        End Sub
    End Class
  
    Private Class MyTemplate
        Implements ITemplate
        Protected lControlEZ As LiteralControl
        Protected lControlDZ As LiteralControl
        Protected lControlBu As LiteralControl
  
        Private nIdCol As Integer
        Private bNurPK As Boolean
        Private nfZahl As Integer
        Sub New(ByVal nIdGruppe As Integer, ByVal bNurPlatzk As Boolean)
            nIdCol = nIdGruppe
            bNurPK = bNurPlatzk
        End Sub
        Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
            Dim table As New Table()
            Dim row1 As New TableRow()
            Dim cell11 As New TableCell()
            Dim cell12 As New TableCell()
            Dim cell21 As New TableCell()
            table.CellPadding = 0
            table.CellSpacing = 0
            table.BorderStyle = BorderStyle.None
            table.Width = Unit.Percentage(100)
            lControlEZ = New LiteralControl()
            lControlEZ.ID = "ES" & nIdCol
            AddHandler lControlEZ.DataBinding, AddressOf lControlEZ_DataBinding
            cell11.Width = Unit.Percentage(100)
            cell11.BorderStyle = BorderStyle.None
            row1.Cells.Add(cell11)
  
            If bNurPK = False Then
                lControlDZ = New LiteralControl()
                lControlDZ.ID = "DS" & nIdCol
  
                AddHandler lControlDZ.DataBinding, AddressOf lControlDZ_DataBinding
  
                lControlBu = New LiteralControl()
                lControlBu.ID = "Buchbar" & nIdCol
                AddHandler lControlBu.DataBinding, AddressOf lControlBu_DataBinding
  
              
  
                cell11.Width = Unit.Percentage(45)
                cell12.Width = Unit.Percentage(45)
                cell21.Width = Unit.Percentage(10)
                cell11.BorderStyle = BorderStyle.None
                cell12.BorderStyle = BorderStyle.None
                cell21.BorderStyle = BorderStyle.None
                row1.Cells.Add(cell12)
                row1.Cells.Add(cell21)
            End If
  
            table.Rows.Add(row1)
  
            cell11.Controls.Add(lControlEZ)
            If bNurPK = False Then
                cell12.Controls.Add(lControlDZ)
                cell21.Controls.Add(lControlBu)
            End If
            container.Controls.Add(table)
        End Sub
        Private Sub boolValue_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim cBox As CheckBox = DirectCast(sender, CheckBox)
            Dim container As GridDataItem = DirectCast(cBox.NamingContainer, GridDataItem)
  
            cBox.Checked = (DirectCast(container.DataItem, DataRowView))("Buchbar" & nIdCol).ToString()
  
        End Sub
        Public Sub lControlEZ_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim l As LiteralControl = DirectCast(sender, LiteralControl)
            Dim container As GridDataItem = DirectCast(l.NamingContainer, GridDataItem)
  
            l.Text = String.Format("{0:C}", (DirectCast(container.DataItem, DataRowView))("ES" & nIdCol))
  
        End Sub
        Public Sub lControlDZ_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim l As LiteralControl = DirectCast(sender, LiteralControl)
            Dim container As GridDataItem = DirectCast(l.NamingContainer, GridDataItem)
            l.Text = String.Format("{0:C}", (DirectCast(container.DataItem, DataRowView))("DS" & nIdCol))
  
        End Sub
        Public Sub lControlBu_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim l As LiteralControl = DirectCast(sender, LiteralControl)
            Dim container As GridDataItem = DirectCast(l.NamingContainer, GridDataItem)
            If (DirectCast(container.DataItem, DataRowView))("Buchbar" & nIdCol).ToString() = "1" Then
                l.Text = "√"
            Else
                l.Text = "-"
  
            End If
  
  
        End Sub
    End Class

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 04 Nov 2010, 11:59 AM
Hi Ulrich,

You can do one of the following things:

+ enclose all your template content in a NOBR element. For example, insert the opening and closing tags as literal controls.
+ enclose (where needed) the table cell content in a NOBR element or inside an additional HTML element with disabled text wrapping, for example: <div style="white-space:nowrap">.........</div>

The second option is better.

http://www.telerik.com/help/aspnet-ajax/grdnowrapforgridcellcontent.html

Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ulrich
Top achievements
Rank 1
answered on 04 Nov 2010, 12:49 PM
Thank you for your reply.

I saw that link you posted before, but I can't seem to apply that solution. The ColumnCreated event is not being called.
I only use Literal controls in the Templates.

My grid runs completely dynamically. It is created dynamically on the webform and the datasource is also set dynamically.

0
Dimo
Telerik team
answered on 04 Nov 2010, 03:16 PM
Hello Ulrich,

ColumnCreated is fired for autogenerated columns only. In all other cases you can set the DataFormatString property manually when adding the column.

The help article was supposed to give a more broader insight on the matter. You don't have to apply the workaround exactly as specified there - the suggestions from my previous message are recommended. Do you have any troubles implementing them?


Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ulrich
Top achievements
Rank 1
answered on 04 Nov 2010, 04:51 PM
Thanks again. Please bear with me because I'm fairly new to ASP.Net.

I'm not sure how to implement your suggestions.

Since we only use templates, I have some problems understanding what part I have to enclose in a NOBR element in order to prevent the wrapping. Also, I'm not sure where I can set the DataFormatString property.
0
Accepted
Dimo
Telerik team
answered on 04 Nov 2010, 07:12 PM
Hi Ulrich,

>> "what part I have to enclose in a NOBR element"

Do it with for the content of each table cell, that needs disabled text wrapping, i.e. modify the way you set the cell's Text property. In case you have cells, which you add controls to (cell.Controls.Add(....)), the do this:

cell.Controls.Add(new LiteralControl("<nobr>"));
cell.Controls.Add( your controls here );
cell.Controls.Add(new LiteralControl("</nobr>"));



Kind regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ulrich
Top achievements
Rank 1
answered on 05 Nov 2010, 09:00 AM
Thanks a lot, that worked.
Tags
Grid
Asked by
Ulrich
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Ulrich
Top achievements
Rank 1
Share this question
or