custom hyperlink for member info pages.

Results 1 to 7 of 7

Thread: custom hyperlink for member info pages.

  1. #1
    Join Date
    Dec 1969
    Posts
    15

    Default custom hyperlink for member info pages.

    Ok, I originally posted this in the databases section thinking it was more of a data access issue. Now however I&#039;ve rethunk the problem and clarified it a bit. So I&#039;ll post it here (probably more appropriate) and hope for a better response.<BR>I have a gridview that I&#039;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 &#039;UserID uniqueidentifier&#039;. Currently it&#039;s showing the hyperlink as follows.<BR>&#060;asp:HyperLink ID="HyperLink1" runat="server" Text=&#039;&#060;%# Eval("UserID") %&#062;&#039; NavigateUrl="~/UserInfo.aspx?UsrID=0"&#062;&#060;/asp:HyperLink&#062;<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&#039;t find a way to get the &#060;%# Eval("UserID") %&#062; 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&#039;m trying to find a decent refference on how to create a custom control that would serve my purpose but so far I&#039;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

  2. #2

    Default RE: custom hyperlink for member info pages.

    Give or a take a typo, it can be done like this:<BR><BR>&#060;asp:HyperLink ID="HyperLink1" runat="server" Text=&#039;&#060;%# GetMemberName((string)DataBinder.Eval("UserID")) %&#062;&#039;<BR> NavigateUrl=&#039;&#060;%#DataBinder.Eval(Containe r.DataItem,"UserID","~/UserInfo.aspx?UsrID=0" %&#062;&#039;&#062;&#060;/asp:HyperLink&#062;

  3. #3

    Default RE: custom hyperlink for member info pages.oops

    gotta use a format string with a placeholder {}<BR>"~/UserInfo.aspx?UsrID={0}"

  4. #4
    Join Date
    Dec 1969
    Posts
    15

    Default RE: custom hyperlink for member info pages.

    I&#039;m having trouble getting that to work. is it in VB or c#? I probably should have mentioned that I&#039;m useing c# so my VB is kinda not so good.


  5. #5

    Default RE: custom hyperlink for member info pages.

    It almost doesn&#039;t matter which language, but the cast expression makes it C#<BR><BR>GetMemberName((string)DataBinder.Eval("UserID"))

  6. #6

    Default RE: custom hyperlink for member info pages.

    Bah, so simple, yet I keep forgetting bits<BR><BR>GetMemberName((string)DataBinder.Eval(Container.DataItem"UserID")) <BR><BR><BR><BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    15

    Default got it working.

    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>&#060;asp:HyperLink ID="HyperLink1" runat="server" Text=&#039;&#060;%# GetMemberName((System.Guid) Eval("UserID")) %&#062;&#039; NavigateUrl=&#039;&#060;%# String.Format("~/UserInfo.aspx?UsrID={0}",Eval("UserID")) %&#062;&#039;&#062;&#060;/asp:HyperLink&#062;<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&#039;ll be happy! :)<BR><BR>I also got the idea of a custom control to work. Here&#039;s the code.<BR>UserInfoHyperlink.ascx<BR>&#060;%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserInfoHyperlink.ascx.cs" Inherits="UserInfoHyperlink" %&#062;<BR>&#060;asp:HyperLink ID="UIHyperLink1" runat="server" Text="UserInfo"&#062;&#060;/asp:HyperLink&#062;<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("&#060;{0}:UserIn foHyperlink runat=\"server\" UsrID=\"0\"&#062; &#060;/{0}:Book&#062;")<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>&#060;uc1:UserInfoHyperlink id="UserInfoHyperlink1" runat="server" UsrID=&#039;&#060;%# Eval("UserID") %&#062;&#039;&#062;&#060;/uc1:UserInfoHyperlink&#062;<BR><BR>Just incase anyone else wanted to see. It&#039;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&#039;ve learned alot from this one.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •