Hi I have a list which pulls out items from a stored procedure. Unfortunately
some of the items it pulls out have apostrophes. This info need to be placed
in a URL but it keeps truncating at the apostrophe. When there is no
apostrophe all is well.
Example
With no apostrophe String = accessories No problem
subcategory.aspx?strSubCategory=Accessories&CategoryID=5
when string = Men's Slippers Truncated URL
http://localhost/dougboys-12-15/subcategory.aspx?strSubCategory=Men
I know the obvious would have been to use keys that were numbers but it was
not done this way for some reason. I realize that with apostrophes a double
quote would be needed but since they are being pulled from the database I can
not do that.
Suggestions?
Hear is the code
______________________________________________________
<ItemTemplate>
<a href='subcategory.aspx?strSubCategory=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory"))%>&CategoryID=<%#
request.querystring(Server.UrlEncode("categoryID")) %>' ><%#
DataBinder.Eval(Container.DataItem, "strSubCategory") %></a>
</ItemTemplate>
LKNewsGroups - 20 Sep 2007 20:22 GMT
OOOPs I meant apostrophe problem
> Hi I have a list which pulls out items from a stored procedure. Unfortunately
> some of the items it pulls out have apostrophes. This info need to be placed
[quoted text clipped - 29 lines]
>
> </ItemTemplate>
Mark Fitzpatrick - 20 Sep 2007 21:02 GMT
Have you tried using the UrlEncode to encode the ' into a valid querystring,
then use UrlDecode to return it to it's normal format?

Signature
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
> Hi I have a list which pulls out items from a stored procedure.
> Unfortunately
[quoted text clipped - 34 lines]
>
> </ItemTemplate>
LKNewsGroups - 20 Sep 2007 21:22 GMT
I did not know about URL Decode. I have Encode in my code but how would I put
the decode into the code. Where would it need to be placed.
<a href='subcategory.aspx?strSubCategory=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory"))%>&CategoryID=<%#
request.querystring(Server.UrlEncode("categoryID")) %>' ><%#
DataBinder.Eval(Container.DataItem, "strSubCategory") %></a>
> Have you tried using the UrlEncode to encode the ' into a valid querystring,
> then use UrlDecode to return it to it's normal format?
[quoted text clipped - 37 lines]
> >
> > </ItemTemplate>
bruce barker - 20 Sep 2007 23:55 GMT
standard URLEncode only xlates ", not ' as html uses " as quote. you
will need to do it yourself. also you need to urlencode all your values,
nor do I understanf the urlencode for the request item lookup.
<script runat="server">
string UrlEncode(string s)
{
return HttpUtility.UrlEncode(s).Replace("'","%27");
}
</script>
<a href='<%#
"subcategory.aspx?strSubCategory=" +
UrlEncode(DataBinder.Eval(Container.DataItem,"strSubCategory"))+
"&CategoryID=" +
UrlEncode(Request.QueryString["categoryID"])%>'
/>
-- bruce (sqlwork.com)
> Hi I have a list which pulls out items from a stored procedure. Unfortunately
> some of the items it pulls out have apostrophes. This info need to be placed
[quoted text clipped - 29 lines]
>
> </ItemTemplate>
LKNewsGroups - 21 Sep 2007 06:48 GMT
Bruce
You are great!
This did the trick
<a href='subcategory.aspx?strSubCategory=<%#
HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory")).Replace("'","%27")%>
Thanks!
> standard URLEncode only xlates ", not ' as html uses " as quote. you
> will need to do it yourself. also you need to urlencode all your values,
[quoted text clipped - 49 lines]
> >
> > </ItemTemplate>