champ_010
asked on
Displaying Special Characters
Hello,
I have some data in my Database that contain the following characters:
- ampersand (&)
- quotations " to represent inches
My problem is that "Oranges & Apples" will only display as "Oranges" and 15"TV will only cause an error. How can I fix this so they appear on the page they same way they exist in the DataBase?
Thanks
I have some data in my Database that contain the following characters:
- ampersand (&)
- quotations " to represent inches
My problem is that "Oranges & Apples" will only display as "Oranges" and 15"TV will only cause an error. How can I fix this so they appear on the page they same way they exist in the DataBase?
Thanks
That might depend on how you are getting these values from the database to your Web page's display.
ASKER
I am outputting them like this inside a DataList ItemTemplate:
<%#DataBinder.Eval(Contain er.DataIte m,"subCatN ame")%>
I don't know how else to do it.
<%#DataBinder.Eval(Contain
I don't know how else to do it.
I'm presuming that the DataList is being bound to some data source object, and that that data source object is being populated from the database somehow....
ASKER
Yes it is nested inside another DataList and get's it's source from a DataRelation Table:
<asp:DataList ID="SiteList" RepeatColumns="3" RepeatDirection="Horizonta l" runat="server">
<ItemTemplate>
<a href="categoriesMain.aspx? catID=<%#D ataBinder. Eval(Conta iner.DataI tem,"categ oryID")%>" <%#DataBin der.Eval(C ontainer.D ataItem,"c ategoryNam e")%></a>
<asp:DataList ID="SiteSubCats" datasource='<%#((DataRowVi ew)Contain er.DataIte m).Row.Get ChildRows( "CatSub")% >' runat="server">
<ItemTemplate>
<a href="products.aspx?subCat ID=<%#Data Binder.Eva l(Containe r.DataItem ,"[\"subCa tID\"]")%> "
&subCatName=<%#DataBinder. Eval(Conta iner.DataI tem,"[\"su bCatName\" ]")%>
</a>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="SiteList" RepeatColumns="3" RepeatDirection="Horizonta
<ItemTemplate>
<a href="categoriesMain.aspx?
<asp:DataList ID="SiteSubCats" datasource='<%#((DataRowVi
<ItemTemplate>
<a href="products.aspx?subCat
&subCatName=<%#DataBinder.
</a>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
ASKER
Sorry--there's an extra " in there from bad copying and pasting--please ignore.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi have several places in my website that display output from the database using:
<%#DataBinder.Eval(Contain er.DataIte m,"subCatN ame")%> and they do the same thing so my problem doesn't necessary pertain to the code layout above, just simply to the out put via DataBinder.Eval.
If it's in the database as:
"Oranges & Apples", it will output as "Oranges"
Also if it is in the database as: 14" TV it will dislay 14" TV but the css formatting will disappear as thought the " closed the tag before style tag kicked in.
<%#DataBinder.Eval(Contain
If it's in the database as:
"Oranges & Apples", it will output as "Oranges"
Also if it is in the database as: 14" TV it will dislay 14" TV but the css formatting will disappear as thought the " closed the tag before style tag kicked in.
ASKER
Thanks--just got your last post. Am trying it out now....
ASKER
Thogek,
It wasn't the url encode at all! When I went back to look, I noticed in the status bar that "Oranges & Apples" show up fine as &category=Oranges & Apples&catID=14 etc.
By accident I noticed that there was a space after &category=Oranges & Apples before &catID so I went to my code and changed:
<a href="products.aspx?subCat ID=<%#Data Binder.Eva l(Containe r.DataItem ,"[\"subCa tID\"]")%>
&subCatName=<%#DataBinder. Eval(Conta iner.DataI tem,"[\"su bCatName\" ]")%>
to put it all on one line--the problem was fixed! The problem was that I split the querystring into several lines to make it easier for viewing on the code page--I guess I should keep it all on one line.
Looking at the "other" places on my website where I am outputing "Oranges & Apples" as only "Oranges"--they are not url links. I retreive the values from a querystring so:
string SubCatName=Request.QuerySt ring["subC atName"].T oString();
To output by: <%=SubCatName%> will only give me "Oranges".
How to fix this?
It wasn't the url encode at all! When I went back to look, I noticed in the status bar that "Oranges & Apples" show up fine as &category=Oranges & Apples&catID=14 etc.
By accident I noticed that there was a space after &category=Oranges & Apples before &catID so I went to my code and changed:
<a href="products.aspx?subCat
&subCatName=<%#DataBinder.
to put it all on one line--the problem was fixed! The problem was that I split the querystring into several lines to make it easier for viewing on the code page--I guess I should keep it all on one line.
Looking at the "other" places on my website where I am outputing "Oranges & Apples" as only "Oranges"--they are not url links. I retreive the values from a querystring so:
string SubCatName=Request.QuerySt
To output by: <%=SubCatName%> will only give me "Oranges".
How to fix this?
In the case of
string SubCatName=Request.QuerySt ring["subC atName"].T oString();
how is the subCatName populated into the QueryString in the first place? (I suspect this is still a case where a preceeding link should have used Server.UrlEncode, as discussed above.)
string SubCatName=Request.QuerySt
how is the subCatName populated into the QueryString in the first place? (I suspect this is still a case where a preceeding link should have used Server.UrlEncode, as discussed above.)
ASKER
You are probably right--I see % in the address bar...am changing now...
ASKER
I got this error:
Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.HttpServerUtil ity.UrlEnc ode(string )' has some invalid arguments
for this:
<a href="categoriesMain.aspx? catID=<%#H ttpContext .Current.S erver.UrlE ncode(Data Binder.Eva l(Containe r.DataItem ,"category ID"))%>&ca tegory=<%# HttpContex t.Current. Server.Url Encode(Dat aBinder.Ev al(Contain er.DataIte m,"categor yName"))%> "><%#DataB inder.Eval (Container .DataItem, "categoryN ame"))%></ a>
Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.HttpServerUtil
for this:
<a href="categoriesMain.aspx?
ASKER
Is there some way to convert it on the page that receives the querystring?
ASKER
Can we replace %20 with ""? it's the spaces that are giving me problems--doesn't look like the & is.
ASKER
ANSWER:
You need to do Convert.ToString();
So:
<a href="categoriesMain.aspx? catID=<%#D ataBinder. Eval(Conta iner.DataI tem,"categ oryID")%>& category=< %#Server.U rlEncode(C onvert.ToS tring(Data Binder.Eva l(Containe r.DataItem ,"category Name")))%> ">
Point awarded anyways for letting me know about Server.Encode.
You need to do Convert.ToString();
So:
<a href="categoriesMain.aspx?
Point awarded anyways for letting me know about Server.Encode.