0

Whenever I bind my descprtion url to the datasource it evaluates the item, but adds these weird "%20" in between.

I.E.

jelly%20fish

this code works perfectly when in my title attribute of my image i.e.

    <li><asp:Repeater ID="Repeater1" runat="server">

<ItemTemplate>
<asp:Image ID="Image1" runat="server"  ImageUrl='<%# "getImage.ashx?ImID="+ Eval("ID")    %>' title='<%# Eval("imagename") %>' DescriptionUrl='<%# Eval("Description") %>' /> 
</ItemTemplate>
</asp:Repeater></li>

How do i decode this descriptionurl?

Here is my c# code:

    SqlConnection connection = new SqlConnection(strcon);
    string querystring = "SELECT image, description ,imagename, id from table where     startdate <= CONVERT (date, SYSDATETIME())and endate >= CONVERT (date, SYSDATETIME())";

    SqlCommand command = new SqlCommand(querystring, connection);

    SqlDataAdapter daimages = new SqlDataAdapter(command);
    DataTable dt = new DataTable();
    daimages.Fill(dt);
    Repeater1.DataSource = dt;

    Repeater1.DataBind();
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60

1 Answers1

1

A space gets encoded as %20 in a URL - it is a special character in a URL.

The code is doing the right thing.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • what should i use instead of descriptionurl so i don't get this special char then – Chris Stewart Apr 10 '12 at 19:07
  • @user967713 - You seem to be getting this in your datasource to begin with. Are you URL encoding this? – Oded Apr 10 '12 at 19:10
  • Sorry, i'm pretty new to the whole web dev thing. No I don't think I am url encoding this. It's taking this description directly from a database i have it stored in. – Chris Stewart Apr 10 '12 at 19:13
  • @user967713 - Are you certain it doesn't have the `%20` in the database then? Did you follow through to see if it does get URL encoded on the way to the page? – Oded Apr 10 '12 at 19:14
  • It defintely doesn't have a %20 in the database, i just looked. Its getting added to the database by the following command: cmd.Parameters.Add("description", imagedescr.Text); if that helps at all. – Chris Stewart Apr 10 '12 at 19:15
  • I do redirect at the very end of the insert with this : string url2 = HttpContext.Current.Request.Url.AbsoluteUri; Response.Redirect(url2); --- would this encode the url somehow? – Chris Stewart Apr 10 '12 at 19:17
  • @user967713 - A redirect doesn't encode anything on the page. And `Eval` doesn't encode either. Somewhere, between the database and `Eval`, the `Description` gets URL encoded. – Oded Apr 10 '12 at 19:19
  • @user967713 - Nothing I can see. – Oded Apr 10 '12 at 19:28