Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   DataGrid displaying line breaks in bound column (http://www.velocityreviews.com/forums/t119260-datagrid-displaying-line-breaks-in-bound-column.html)

=?Utf-8?B?Um9za28=?= 02-09-2006 05:37 AM

DataGrid displaying line breaks in bound column
 
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

=?Utf-8?B?Um9za28=?= 02-09-2006 05:56 AM

RE: DataGrid displaying line breaks in bound column
 
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


=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= 02-09-2006 06:28 AM

RE: DataGrid displaying line breaks in bound column
 
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


=?Utf-8?B?Um9za28=?= 02-09-2006 02:41 PM

RE: DataGrid displaying line breaks in bound column
 
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


=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= 02-09-2006 05:22 PM

RE: DataGrid displaying line breaks in bound column
 
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


mohanms 03-21-2011 03:37 AM

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

CraigPaardekooper 12-20-2011 11:48 AM

Easy way to add line breaks to Datagrid bound columns
 
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.


All times are GMT. The time now is 10:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.