Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid displaying line breaks in bound column

Reply
Thread Tools

DataGrid displaying line breaks in bound column

 
 
=?Utf-8?B?Um9za28=?=
Guest
Posts: n/a
 
      02-09-2006
Hello - I'm displaying a SQL Server text field in a bound column. The text
field has line breaks (CrLf - 0D0A) but the text displays in a long string in
the DataGrid. Anybody know how to display them?
--
Rosko
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Um9za28=?=
Guest
Posts: n/a
 
      02-09-2006
Sorry...forgot to mention this is ASP.NET on our intranet.
--
Rosko


"Rosko" wrote:

> Hello - I'm displaying a SQL Server text field in a bound column. The text
> field has line breaks (CrLf - 0D0A) but the text displays in a long string in
> the DataGrid. Anybody know how to display them?
> --
> Rosko

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      02-09-2006
Rosko,

Use a databinding expression that replaces the occurrences of
Environment.NewLine with "<br/>" as I did in this demo:
http://www.societopia.net/Samples/Da...Hierarchy.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Rosko" wrote:

> Sorry...forgot to mention this is ASP.NET on our intranet.
> --
> Rosko
>
>
> "Rosko" wrote:
>
> > Hello - I'm displaying a SQL Server text field in a bound column. The text
> > field has line breaks (CrLf - 0D0A) but the text displays in a long string in
> > the DataGrid. Anybody know how to display them?
> > --
> > Rosko

 
Reply With Quote
 
=?Utf-8?B?Um9za28=?=
Guest
Posts: n/a
 
      02-09-2006
Works great. So simple, so elusive. Thanks so much for your help!
--
Rosko


"Phillip Williams" wrote:

> Rosko,
>
> Use a databinding expression that replaces the occurrences of
> Environment.NewLine with "<br/>" as I did in this demo:
> http://www.societopia.net/Samples/Da...Hierarchy.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Rosko" wrote:
>
> > Sorry...forgot to mention this is ASP.NET on our intranet.
> > --
> > Rosko
> >
> >
> > "Rosko" wrote:
> >
> > > Hello - I'm displaying a SQL Server text field in a bound column. The text
> > > field has line breaks (CrLf - 0D0A) but the text displays in a long string in
> > > the DataGrid. Anybody know how to display them?
> > > --
> > > Rosko

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      02-09-2006
You are quite welcome.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Rosko" wrote:

> Works great. So simple, so elusive. Thanks so much for your help!
> --
> Rosko
>
>
> "Phillip Williams" wrote:
>
> > Rosko,
> >
> > Use a databinding expression that replaces the occurrences of
> > Environment.NewLine with "<br/>" as I did in this demo:
> > http://www.societopia.net/Samples/Da...Hierarchy.aspx
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Rosko" wrote:
> >
> > > Sorry...forgot to mention this is ASP.NET on our intranet.
> > > --
> > > Rosko
> > >
> > >
> > > "Rosko" wrote:
> > >
> > > > Hello - I'm displaying a SQL Server text field in a bound column. The text
> > > > field has line breaks (CrLf - 0D0A) but the text displays in a long string in
> > > > the DataGrid. Anybody know how to display them?
> > > > --
> > > > Rosko

 
Reply With Quote
 
mohanms mohanms is offline
Junior Member
Join Date: Mar 2011
Posts: 1
 
      03-21-2011
hi guys.
its not workin for me...
im using Ajax grid. but the methods r almost the same. im jut bindin the data from the front end insead of the backend. the rest should be similar.

when i used the methods suggested, "<br/ >". its displayin the <br/ > instead of movin to newline. any help? thanks
 
Reply With Quote
 
CraigPaardekooper CraigPaardekooper is offline
Junior Member
Join Date: Dec 2011
Posts: 1
 
      12-20-2011
So you want to add line breaks to a datagrid, and you are using bound columns.

You can achieve this as follows -

1. When you insert text into your database use - replace(vbcrlf, "<br>")

2. When you click on the Edit button (ie the datagrid_editcommand) column then use - replace("<br", vbcrlf) . The way I do this is I create a Method and call it immediately after the databinding event.



ProtectedSub GridView1_EditCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles GridView1.EditCommand

GridView1.EditItemIndex = e.Item.ItemIndex
Dim ds AsDataSet = GetDataset()

BindGrid(ds)

AddLineBreaks()

EndSub


The AddLineBreaks Method loops through all the rows of the datagrid, and when I find the row that is in EditMode, then I can replace the "<br>" in that row with vbcrlf

Sub AddLineBreaks()

For i = 0 To GridView1.Items.Count - 1

If GridView1.Items(i).ItemType = ListItemType.EditItem Then

CType(GridView1.Items(i).Cells(1).Controls(0), TextBox).TextMode = TextBoxMode.MultiLine

CType(GridView1.Items(i).Cells(1).Controls(0), TextBox).Width = System.Web.UI.WebControls.Unit.Pixel(400)

CType(GridView1.Items(i).Cells(1).Controls(0), TextBox).Height = System.Web.UI.WebControls.Unit.Pixel(100)

CType(GridView1.Items(i).Cells(1).Controls(0), TextBox).Text = CType(GridView1.Items(i).Cells(1).Controls(0), TextBox).Text.Replace("<br>", vbCrLf)

EndIf

Next

Note that this will also allow you to resize the textboxes during edit mode for a datagrid

The Items collection of a datagrid are it's rows, and each row contains a collection of Cells, and each cell conatins a collection of controls. So you can speify which cells you want to replace <br> with vbcrlf, and which textboxes you want to resize.

3. When you click on the update button then use - replace(vbcrlf, "<br") . The update button in a datagrid triggers the update_command event. This will read the contents of a textbox while in edit mode, and replace vbcrlf with <br>

YOURCOLUMNNAME =
CType(e.Item.Cells(1).Controls(0), TextBox).Text.Replace(vbCrLf, "<br>")

I hope this helps datagrid people with both line breaks and with resizing editmode textboxes.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner: read $array with line breaks line by line Marek Stepanek Perl Misc 12 09-02-2006 10:27 AM
Sortable column on DataGrid -- column header not displaying Teej ASP .Net Datagrid Control 2 08-15-2006 06:23 PM
Move bound column to right of dynamic column in datagrid? John E. ASP .Net Datagrid Control 3 03-28-2005 01:29 PM
Move bound column to right of dynamic column in datagrid? John E. ASP .Net 3 03-25-2005 09:19 PM
Bound Column or Template Column (w dAdapater?) in DataGrid Ravichandran Mahalingam ASP .Net Datagrid Control 0 01-09-2004 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57