Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a datagrid that has 3 columns that i have set up for the user to edit. One of the columns contains a URL. I have it set up where they can edit the URL but they can't actually click on it and navigate to it. I would like that functionality without losing the editing capabilities. So right now I have 2 issues: 1) all of the hyperlinks, when clicked, lead to relative paths and not absolute urls, so they fail and 2) when the hyperlink is clickable I lose the ability to edit it.

 

Here is what I started with. This has al fields editable but the hyperlink is just a url, not a hyperlink (you can't click it):

<Columns>
<asp:BoundColumn DataField="field_name" ReadOnly="True" HeaderText="Field Name"></asp:BoundColumn>
<asp:BoundColumn DataField="display_order" HeaderText="Display Order"></asp:BoundColumn>
<asp:BoundColumn DataField="hyperlink_value" HeaderText="Hyperlink"></asp:BoundColumn>
<asp:BoundColumn DataField="alias" HeaderText="Alias"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="<img src=./images/spell.ico border=0 align=absmiddle alt='Save changes'  height=35 >" CancelText="<img src=./images/stop.ico border=0 align=absmiddle alt='Cancel editing'  height=35 >" EditText="<img src=./images/write.ico border=0 align=absmiddle alt='Edit this item'  height=35 >"></asp:EditCommandColumn>
</Columns>

 

 

Then I tried to change that column to a hyperlinkColumn like so:

 

<asp:HyperLinkColumn DataTextField="hyperlink_value" DataNavigateUrlField="hyperlink_value" DataNavigateUrlFormatString="{0}" HeaderText="Hyperlink"></asp:HyperLinkColumn>

 

That gets me a hyperlink but I lose the ability to edit and when a user clicks on a hyperlink like http://www.cnn.com they get directed to http://localhost/mydir/www.conn.com which, as you can imagine, fails.

 

The last thing I tried was:

 

<asp:TemplateColumn HeaderText="Link">
	<ItemTemplate>
	<asp:HyperLink Runat =server 
	NavigateUrl ='<%#GetURL(DataBinder.Eval(Container.DataItem, "Link"))%>' >
	<%#DataBinder.Eval(Container.DataItem, "Link")%>
	</asp:HyperLink>
	</ItemTemplate>
</asp:TemplateColumn>

 

Along with

 

	public string GetURL (string fldval)
	{
		if (fldval.IndexOf("http://") > 0)
		{
			return fldval;
		}
		else
		{
			return "http://" + fldval;
		}
	}

 

But that didn't work either.

Can this be done? Any suggestions?

Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...