Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line breaks in Datagrid 1

Status
Not open for further replies.

AndyApp

Programmer
Dec 20, 2001
259
GB
Hi,

I've found a number of possibles for this but nothing I've tried has worked.

The users can put data into SQL Server (2000) with line breaks on if they want. However, when I return the data to a datagrid it doesn't recognise the line breaks and it all becomes unreadable.

There must be an easy way to get the bound column to use line breaks?

"Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway" - Jim Davis (Garfield)
 
You could use the Replace command to replace carriage returns and line feeds with <br> tags.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ummm. I could. If I knew how?

&quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
change ur bind as follows:
<%# LineFeed(DataBinder(.....)) %>


write a function called LineFeed
function LineFeed(TheVal)
return TheVal.replace(chr(13),"<br />")
end function

Known is handfull, Unknown is worldfull
 
I get a 'Compilation Error'.
'DataBinder' is a type and cannot be used as an expression.

&quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
>>DataBinder(.....)

is just what u put in the datagrid's template.
what type of template column are u using to display content???



Known is handfull, Unknown is worldfull
 
Code:
<asp:templatecolumn headertext="ISSUE" visible="True">
  <itemtemplate>
    <asp:label runat="server" text=<%# LineFeed(DataBinder("Issue")) %>></asp:label>
  </itemtemplate>
</asp:templatecolumn>

is the code within the datagrid.

Code:
Public Shared Function LineFeed(ByVal TheVal)
    Return TheVal.replace(Chr(13), "<br />")
End Function

is the code in the code behind page

&quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
<asp:label runat="server" text=<%# LineFeed(DataBinder.Eval(Container.Dataitem,"Issue")) %>></asp:label>


Known is handfull, Unknown is worldfull
 
Hi this has all worked A OK, however. I've put textboxes in the edititemtemplate section but whenever i try to grab the contents in the code behind page .net doesn't recognise the textboxes as textboxes it says they're literalcontrols.

This appears fine at first but whenever I take the values out of a literalcontrol to update the database it just completely messes the data up.

Instead of "test" I get " " (loads of blank space). When the user clicks edit or update I'm not running the text through the replace functions as above.

&quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
can u give the edit template once more???

Known is handfull, Unknown is worldfull
 
It's ok I managed to figure it out. Because the column was a template column .NET puts white space in front of the textbox in edit mode. So when you do control(0) what you're trying to access is a literal control that contains white space! So in a way I guess it was right. But why you'd want to access it is anybodys guess! Just use control(1) and it sees the textbox.
thanks anyway vbkris

&quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
i would suggest that u use FindControl() method...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top