3

I am trying to read a querystring and then use this to run a query and display the results for that variable. Very simple.

Unfortunately some of the names have special characters within them and as a result I am not using the full name when running the query on the second page.

i.e. name might be equal to "chas & dave", but the querystring is only giving me back "chas" on the second page and when I search for chas I get no results. Any tips, I seem to have two characters causing an issue "&" and "#".

<asp:hyperlinkcolumn datatextfield="merchant_name"
    datanavigateurlfield="merchant_name"
    datanavigateurlformatstring="writing_out.aspx?id={0}"
    headertext="Merchant Name" />
Barry
  • 63
  • 7

2 Answers2

0

You need to use HttpUtility as follows

System.Web.HttpUtility.UrlEncode(string url)

and use that.

For more details
http://www.dotnetperls.com/httputility

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • sorry i can see the examples on the page provided, but cant get it to work within my datagrid. I have posted the hyperlink column code above. how would i modify this? – Barry Feb 03 '14 at 12:22
  • @Barry you can use databound event to change the url. You can change the values before binding to the grid or any control. – शेखर Feb 03 '14 at 12:38
  • sorry, i am a bit confused. Are you suggesting i need to create a datatable, add a column which has the encoded URL and then use this field to assign to the datanavigateurlfield property? – Barry Feb 03 '14 at 13:03
0
<asp:TemplateColumn>
<HeaderTemplate>
    Merchant Name
</HeaderTemplate>
<ItemTemplate>
    <asp:HyperLink ID="mer_name" runat="server" NavigateUrl='<%# "acc_dec.aspx?id=" + HttpUtility.Urlencode(Eval("merchant_name").ToString())  %>' Text='<%# container.dataitem("merchant_name") %>' />
    </ItemTemplate>
</asp:TemplateColumn>
Barry
  • 63
  • 7