myValue = myValue.Replace(vbCrLf, "<br />")
In C#:
myValue = myValue.Replace("\n", "<br />");
Edited by SomeNewKid. Please post code between<code> and</code> tags.
Peter: Thanks for the input. It makes sense - but being as inexperienced as I am - where would I insert the code? In the same subroutine as the dataReader? Below is the code for the subroutine with the dataReader and the html that outputs it to the webpage.
void commonName_SelectedIndexChanged(object sender, EventArgs e) {
string varSQL="SELECT TOP 2 Photos.SmallPhotoPathway, Photos.SmallPhotoFilename, birdList.family, birdList.commonName, Photos.photoQuality," +
"Photos.contributor, Identification.idCharacteristics FROM (birdList LEFT JOIN Photos ON birdList.commonName = Photos.commonName) INNER JOIN Identification ON" +
"birdList.commonName = Identification.commonName WHERE birdList.commonName=@.param and Photos.permission=Yes ORDER BY birdList.family," +
"birdList.commonName, Photos.photoQuality"; OleDbConnection objConn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\BirdBrain\\BirdBrainDb.mdb");
OleDbCommand objCmd =new OleDbCommand(varSQL, objConn);
OleDbParameter param=new OleDbParameter();
param = objCmd.Parameters.Add("@.param", OleDbType.Char);
param.Direction=ParameterDirection.Input;
param.Value=commonNameList.SelectedItem.Value;
OleDbDataReader objReader;
objConn.Open();
objReader=objCmd.ExecuteReader();
repeatBirds.DataSource=objReader;
repeatBirds.DataBind();
objReader.Close();
objConn.Close();
}
</script>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
Family Name:
Common Names within Family:
</p>
<p>
</p>
<form runat="server">
<p>
<asp:ListBox id="birdFamily" runat="server" AutoPostBack="True" OnSelectedIndexChanged="birdFamily_SelectedIndexChanged" Width="250px"
Height="275px" datatextfield="family"></asp:ListBox>
</p>
<p>
</p>
<p>
<asp:ListBox id="commonNameList" style="Z-INDEX: 100; LEFT: 415px; POSITION: absolute; TOP: 60px" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="commonName_SelectedIndexChanged" Width="250px" Height="275px" DataTextField="commonName"></asp:ListBox>
</p>
<p>
<asp:Repeater id="repeatBirds" Runat="Server" EnableViewState="False">
<ItemTEMPLATE>
<table border="2" width="350" align="center">
<tr></tr>
<tr>
<td>
<p>
Photo: <img src="http://pics.10026.com/?src=<%# DataBinder.Eval(Container.DataItem,"SmallPhotoPathway") % /><%# DataBinder.Eval(Container.DataItem,"SmallPhotoFilename") %>"
</p>
</td>
</tr>
<br />
<tr>
<td>
<p>
Scientific Family Name: <%# DataBinder.Eval(Container.DataItem,"family") %>
</p>
</td>
</tr>
<br />
<tr>
<td>
<p>
Common Name: <%# DataBinder.Eval(Container.DataItem,"commonName") %>
</p>
</td>
</tr>
<br />
<tr>
<td>
<p>
Photo Quality: <%# DataBinder.Eval(Container.DataItem,"photoQuality") %>
</p>
</td>
</tr>
<br />
<tr>
<td>
<p>
Copyright: <%# DataBinder.Eval(Container.DataItem,"contributor") %>
</p>
</td>
</tr>
<br />
<tr>
<td>
<p>
Bird Description: <%# DataBinder.Eval(Container.DataItem,"idCharacteristics") %><align="left" / / />
</p>
</td>
</tr>
<br />
</tr>
</table>
</ItemTEMPLATE>
</asp:Repeater>
</p>
</form>
</body>
</html>
You can do it anywhere you like, including inside the Repeater itself, e.g.
DataBinder.Eval(Container.DataItem,"photoQuality").Replace("\n", "<br />");
Peter: I tried it with great hope - but unfortunately received this error. Any further ideas? Greatly appreciate your time and assistance.
Compiler Error Message: CS0117: 'object' does not contain a definition for 'Replace'
Source Error:
Line 169: <td>
Line 170: <p>
Line 171: Bird Description: <%# DataBinder.Eval(Container.DataItem,"idCharacteristics").Replace("\n", "<br />") %>
Line 172: </p>
Line 173: </td
Source File: D:\BirdBrain\ASPScriptsTest\ASP\dbTest_SQL_twoListboxes8-htmlFormatted.aspx Line: 171
What datatype is this idCharacteristics field?
Try explicitly converting it to a string first, like this:
DataBinder.Eval(Container.DataItem,"idCharacteristics").ToString().Replace("\n", "<br />")
That was it - Thanks very much - it is a load of my mind. Best Regards, Robert
0 comments:
Post a Comment