Sign in to follow this  
sathenzar

[.net] Visual Studio 2005 seems limited

Recommended Posts

Hey I noticed their dataview method seems really limited. You can't make the results display an url. Example: a guestbook that displays a link of each persons name like previewMessage.aspx?guestID=1. They're all static. Is there a way around this? Without programming the whole code yourself to display the data?

Share this post


Link to post
Share on other sites
Which version of it are you using?


There are a few:

Express
Standard
Professional
Enterprise architect etc, but I dont bother looking at those because...price range

Share this post


Link to post
Share on other sites
It sounds like you're describing a problem with ASP not a problem with visual studio. Visual Studio is not a language, it's a tool with which you can compile/link languages like C++/VB/.NET/etc

Are you asking how to display a url with ASP?

-me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If I understood You correctly, then this is how I do it in my datagrid:
aspx page:



' runat="server">Clicky



codebehind:

public string GetLink(object id)
{
return String.Format("mypage.aspx?id={0}", id.ToString());
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If I understood You correctly, then this is how I do it in my datagrid:
aspx page:

_asp:TemplateColumn_
_ItemTemplate_
_asp:HyperLink ID="link" NavigateUrl='_%# GetLink(DataBinder.Eval(Container.DataItem, "id")) %_' runat="server"_Clicky_/asp:HyperLink_
_/ItemTemplate_
_/asp:TemplateColumn_

codebehind:

public string GetLink(object id)
{
return String.Format("mypage.aspx?id={0}", id.ToString());
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
If I understood You correctly, then this is how I do it in my datagrid:
aspx page:

_asp:TemplateColumn_
_ItemTemplate_
_asp:HyperLink ID="link" NavigateUrl='_%# GetLink(DataBinder.Eval(Container.DataItem, "id")) %_' runat="server"_Clicky_/asp:HyperLink_
_/ItemTemplate_
_/asp:TemplateColumn_

codebehind:

public string GetLink(object id)
{
return String.Format("mypage.aspx?id={0}", id.ToString());
}


Are you trying to display the URL? If you are, then just set the 'Text' property of the asp:hyperlink to the same value as the 'NavigateUrl' property.

I.E.



<ItemTemplate>
<asp:HyperLink runat="server" id="linkName" NavigateUrl='<%# GetLink(DataBinder.Eval(Container.DataItem, "id")) %>' Text='<%# GetLink(DataBinder.Eval(Container.DataItem, "id")) %>'>
</ItemTemplate>



Share this post


Link to post
Share on other sites
O wow, I can't believe I was that blind...I feel extreamly stupid right now. I looked at the code again and there is the code blocks of <ItemTemplate> like someone said above. Thanks for all your help guys I really appreciate it and sorry for wasting your time. I should've looked closer...I'll get my eye's checked today :)

Share this post


Link to post
Share on other sites
real quick though, I tried to edit the template tag but it's not working out correctly, I tried the implementation of the block described above. Then I tried it this way:

<asp:Label ID="guestIDLabel" runat="server" Text=' + ">" + <%# Eval("guestID") %> + ""'></asp:Label><br />


neither of the two worked they output parts of the code above. Thanks.

Share this post


Link to post
Share on other sites
Nvm I'm back again. This is is driving me up the wall. All I want to do is preform a simple task of putting a link that links to a page and supplies the damn id and the thing just simple is thumbing it's nose at me trying to p*** me off. I have this line:

<asp:HyperLink runat="server" id="guestIDLabel" NavigateUrl='testpage.aspx?id=<%# Eval("guestID") %>' Text='<%# Eval ("guest_name") %>'></asp:HyperLink>


and it doesn't work. The link then reads (when in debugging mode) testpage.aspx?id=<%# Eval("guestID") %> and it's really getting me mad. It shouldn't be that hard to display a link or is ASP.NET that incompetant?

/rant

Share this post


Link to post
Share on other sites
I don't really see what's wrong with your code. It should work just fine the way you're doing it.
But if you don't manage to get it working you can try the following

Note: I'm not yet familier with ASP.NET 2.0. But I guess the DataView works similar to ASP.NET 1.1's DataGrid. So I will give you an example using a good old DataGrid

In your aspx page, in the ItemTemplate, give an ID to your Hyperlink control (e.g. id="MyLink").

Then in the source page, attach an Eventhandler to the DataGrid's ItemDataBound Event (I will do this in VB.NET as I'm not a C# guy
[source lang=vb]
Private Sub MyGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyGrid.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

dim MyLink as HyperLink
//The next line uses the FindControl method to return the control which
//corresponds to the control having id="MyLink"
//and then casts it to a Hyperlink
MyLink = Ctype(e.Item.FindControl("MyLink"), Hyperlink)
MyLink.NavigateUrl = "Link goes here"

End If

End Sub




I hope this helps you.
If .NET 2's DataView works differently then I'm sorry, but I can't help

[Edit]
Ooops, double post. Sorry. Can some moderator please remove the previous post?
[/Edit]

Share this post


Link to post
Share on other sites
Quote:
Original post by rpg_code_master
Try using DataBinder.Eval(Container.DataItem, "guestID") instead of just Eval("guestID")


Someone already suggested this. But it seems that best practice with .NET 2.0 would be to just use Eval("guestID"). Also it is certainly worth giving it a shot.

Anyway, I guess this post was rather pointless :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this