Click here to Skip to main content
12,299,947 members (52,634 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21.3K views
7 bookmarked
Posted

NoWrap in an ASP.NET DataGrid

, 16 Apr 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Implementing NoWrap in an ASP.NET DataGrid.

Introduction

Today I had big trouble with text wrapping in an ASP.NET DataGrid. No matter what I did in the CSS, the grid's <td>/<tr> came out like this:

Scratching my head

So I scratched my head for a while, Googled a bit, and tried HttpUtility.HtmlEncode. No success. It does not convert a space to a non-breaking space. So I scratched again and then added this code in a module:

Option Strict On
Option Explicit On
Imports System.Runtime.CompilerServices

Module Extensions

  < Extension() > _
  Public Function SpaceToNbsp(ByVal s As String) As String
    Dim space As String = " "
    Return s.Replace(" ", space)
  End Function

End Module

In the code above:

Dim space As String = " "

should be

Dim space As String = ""&nbsp;""

Then I wrote this code:

row("Borgnummer") = i.OrgNummer.Text & " / ".SpaceToNbsp & i.PersNummer.Text

Voila! It came out just as I wanted:

License

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

Share

About the Author

Michael Rosqvist
Web Developer
Sweden Sweden
No Biography provided

You may also be interested in...

Comments and Discussions

 
Generalyou can use nobr tag in a template column to achive this Pin
D.Sridhar17-Apr-08 3:14
memberD.Sridhar17-Apr-08 3:14 
GeneralMaybe this... Pin
digital man 16-Apr-08 3:35
member digital man 16-Apr-08 3:35 
GeneralRe: Maybe this... Pin
kurtsune16-Apr-08 8:14
memberkurtsune16-Apr-08 8:14 
GeneralThis can work too Pin
leppie 16-Apr-08 3:10
member leppie 16-Apr-08 3:10 
GeneralRe: This can work too Pin
kurtsune16-Apr-08 8:15
memberkurtsune16-Apr-08 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160525.2 | Last Updated 16 Apr 2008
Article Copyright 2008 by Michael Rosqvist
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid