tags:

views:

10836

answers:

7

My code is in c# asp.net 3.5

In the following code the "Msg" has many words with spaces and characters (eg:Failed to prepare Sync Favorites : Directory does not exist: \STL-FNP-02\ryounes$\Sync\Favorites). This "Msg" is pulled from database to a gridview. I am not able to create hyperlink for this "Msg" in gridview. Since it has spaces it is not creating hyperlink.

I need to create hyperlink for this "Msg" and latter use it in linq query.

I think one shud either use eval or url encoder. I am not sure how to do it. Can anyone say how to go about it?

 <asp:HyperLinkField DataTextField="Msg" HeaderText="Msg" DataNavigateUrlFields="Msg"   
  DataNavigateUrlFormatString="Sync.aspx?Msg={0}" />
A: 

It doesn't create the link as it is not a valid URL, rather than using a hyperlink column most likely you are going to need to migrate to a template and manage it yourself, or at minimum do some formatting on it.

I would be cautious regardless of making that a hyperlink, where is it going to go anway?

If there is a specific place based on message that you should be going, calculate that BEFORE you bind to the grid...

Mitchel Sellers
A: 

It sounds like you need to url-encode the string so that the words and spaces can exist as one variable in the query string. Take a look at this function: http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

Rafe
A: 

Yes for the Grid in goes to a linq query which is as follows and then bind it to grid.

  String Data= Request.Querystring["Msg"]; 
  var query6 = from u in dc1.syncback_logs
                             where u.Msg == Data
                             orderby u.TimeOfMessage descending
                             select u;
                GridView1.DataSource = query6;
                GridView1.DataBind();

Can you please tell me how to create a template?

+3  A: 

The easiest way to get around it is to use something like

<asp:TemplateField HeaderText="Msg"> 
    <asp:HyperLink runat="server" Text='<%# HttpUtility.UrlEncode(Eval("Msg")) %>' NavigateUrl='<%#Eval("Msg")%>' />
</asp:TemplateField>

Not 100% certain that the syntax is correct but you get the general idea

Marcus King
A: 

Hey I tried the follwiong code :

<asp:TemplateField HeaderText="Message">
<ItemTemplate>
   <asp:HyperLink ID="hyper" runat="server" NavigateUrl='<%#"Sync.aspx?Msg="+HttpUtility.URLEncode(Eval("Msg").ToString())%>' Text='<%# HttpUtility.UrlEncode(Eval("Msg")) %>' />
</ItemTemplate>
</asp:TemplateField>

But I am getting the following error:

" Compiler Error Message: CS0117: 'System.Web.HttpUtility' does not contain a definition for 'URLEncode'"

Can anyone tell wat this means?

Try NavigateUrl='<%#string.Format("Sync.aspx?Msg={0}", HttpUtility.UrlEncode(Eval("Msg"))%>' Be careful of the casing
Marcus King
A: 

how can i use Hyperlink button in gridview. means when i run my programe,all data is display in gridview,but i want hyperlink in gridview,when i will click in hyperlink it will show the select path which is in gridview,means if there is pdf file path then i just click on this hyper ling then i can see the pdf file.

can u tell me how can i do this? reply me in below mail id plz

[email protected]

A: 

Dear Sir i want to craet a Hyperlink in a whole column of Roll No. Data in GridView so Please send me require code..