Ok, I originally posted this in the databases section thinking it was more of a data access issue. Now however I've rethunk the problem and clarified it a bit. So I'll post it here (probably more appropriate) and hope for a better response.<BR>I have a gridview that I've created a custom template for. In that template I have a place where I need a hyperlink to go to the contact information page of the user associated with a piece of information. My problem is two-fold. The database stores the refference in the table as 'UserID uniqueidentifier'. Currently it's showing the hyperlink as follows.<BR><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("UserID") %>' NavigateUrl="~/UserInfo.aspx?UsrID=0"></asp:HyperLink><BR>I need the Text value to equal the username. For wich I wrote the following function.<BR>public string GetMemberName(string UsrID) {<BR>if (UsrID != null) {<BR>System.Guid mUID = new System.Guid(UsrID);<BR>if (mUID != null) {<BR>MembershipUser mUsr = Membership.GetUser(mUID);<BR>return mUsr.UserName;<BR>}<BR>}<BR>return null;<BR>}<BR>But I have no idea how to call the function from the hyperlink.<BR>The other problem is that the UsrID= is currently hard coded to 0 because I can't find a way to get the <%# Eval("UserID") %> databinding to work in the middle of a string.<BR>If anyone has any suggestions on how to get this working please let me know.<BR>My current working theroy, Custom controls. I'm trying to find a decent refference on how to create a custom control that would serve my purpose but so far I'm not even sure how to create custom controls.<BR>Any help on how to use the asp:hyperlink control the way I need and/or any help on how to create a custom control that would do what I need would be appreciated.<BR>Thanks,<BR>Rob
Give or a take a typo, it can be done like this:<BR><BR><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# GetMemberName((string)DataBinder.Eval("UserID")) %>'<BR> NavigateUrl='<%#DataBinder.Eval(Containe r.DataItem,"UserID","~/UserInfo.aspx?UsrID=0" %>'></asp:HyperLink>
I'm having trouble getting that to work. is it in VB or c#? I probably should have mentioned that I'm useing c# so my VB is kinda not so good.
Thanks for the reply. I got it working. A little different than what you had but. The problem truned out to be in the Navigation URL part. I did it like this.<BR><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# GetMemberName((System.Guid) Eval("UserID")) %>' NavigateUrl='<%# String.Format("~/UserInfo.aspx?UsrID={0}",Eval("UserID")) %>'></asp:HyperLink><BR>It also complained about the String to System.Guid cast and I realized my function was just casting it back right away so I did this.<BR> public string GetMemberName(string UsrID) {<BR> if (UsrID != null && UsrID != string.Empty) {<BR> System.Guid mUID = new System.Guid(UsrID);<BR> if (mUID != null) {<BR> MembershipUser mUsr = Membership.GetUser(mUID);<BR> return mUsr.UserName;<BR> }<BR> }<BR> return null;<BR> }<BR> public string GetMemberName(System.Guid mUID) {<BR> MembershipUser mUsr = Membership.GetUser(mUID);<BR> return mUsr.UserName;<BR> }<BR>Now if it returns a string or System.Guid it'll be happy! :)<BR><BR>I also got the idea of a custom control to work. Here's the code.<BR>UserInfoHyperlink.ascx<BR><%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserInfoHyperlink.ascx.cs" Inherits="UserInfoHyperlink" %><BR><asp:HyperLink ID="UIHyperLink1" runat="server" Text="UserInfo"></asp:HyperLink><BR><BR>UserInfoHyperlink.ascx. cs<BR>using System;<BR>using System.Data;<BR>using System.Configuration;<BR>using System.Collections;<BR>using System.Web;<BR>using System.Web.Security;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.WebControls.WebParts;<BR>using System.Web.UI.HtmlControls;<BR><BR>using System.ComponentModel;<BR>using System.Security.Permissions;<BR><BR><BR><BR>[<BR>AspNetHostingPermission(SecurityAction.Deman d, Level = AspNetHostingPermissionLevel.Minimal),<BR>AspNetHo stingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),<BR>DefaultP roperty("UsrID"),<BR>ToolboxData("<{0}:UserIn foHyperlink runat=\"server\" UsrID=\"0\"> </{0}:Book>")<BR>]<BR><BR>public partial class UserInfoHyperlink : System.Web.UI.UserControl<BR>{<BR> private string UID;<BR> protected void Page_Load(object sender, EventArgs e)<BR> {<BR><BR> }<BR> [<BR> Bindable(true),<BR> Category("Appearance"),<BR> DefaultValue(""),<BR> Description("The UserID of the user to get the info for."),<BR> Localizable(true)<BR> ]<BR> public string UsrID {<BR> get {<BR> return (UID == null)?string.Empty:UID;<BR> }<BR> set {<BR> UID = value;<BR> UIHyperLink1.Text = GetMemberName(UID);<BR> UIHyperLink1.NavigateUrl = "~/UserInfo.aspx?UsrID=" + UID;<BR> }<BR> }<BR><BR> private string GetMemberName(string UsrID) {<BR> if (UsrID != null && UsrID != string.Empty) {<BR> System.Guid mUID = new System.Guid(UsrID);<BR> if (mUID != null) {<BR> MembershipUser mUsr = Membership.GetUser(mUID);<BR> return mUsr.UserName;<BR> }<BR> }<BR> return null;<BR> }<BR><BR> }<BR><BR>and it gets used like this.<BR><uc1:UserInfoHyperlink id="UserInfoHyperlink1" runat="server" UsrID='<%# Eval("UserID") %>'></uc1:UserInfoHyperlink><BR><BR>Just incase anyone else wanted to see. It's good to know more than one way to do something cause you never know when the techneque might come in handy.<BR>Thank you "the_original_andrew" I've learned alot from this one.<BR>
Bookmarks