www.webdeveloper.com
Results 1 to 3 of 3

Thread: Display the Page.User.Identity.Name in the datagrid hyperlink column

  1. #1
    Join Date
    Dec 2005
    Posts
    13

    Display the Page.User.Identity.Name in the datagrid hyperlink column

    Hi,

    I am using asp.net, C# and sql server

    I have a gridview control which looks like the following

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

    <Columns>

    <asp:HyperLinkField DataTextField="Name" DataNavigateUrlFields=""

    DataNavigateUrlFormatString="http://www.anrdoezrs.net/click-1850716-10387413?sid={0}"/>

    <asp:BoundField DataField="Decsription"/>

    </Columns>

    </asp:GridView>

    In the DataNavigateUrlFormatString="http://www.anrdoezrs.net/click-1850716-10387413?sid={0}

    i want to replace the {0} with the logged in user's identity which is Page.User.Identity.Name.

    How should i do it should i do it in the DataNavigateUrlFields property or in the code behind pages.

    I tried creating a method in the code behind file as follows to get the identity and displaying it

    public string GetMemberID()
    {
    return Page.User.Identity.Name.ToString();
    }


    and tried calling it in the datagrid hyperlink column as follows

    <asp:HyperLinkField DataTextField="Name" DataNavigateUrlFormatString='<%#

    string.Format("http://www.anrdoezrs.net/click-1850716-10387413?sid={0}", GetMemberID()) %>'/>


    but got an error message as follows :


    Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.HyperLinkField does not have a DataBinding event.
    How should i go about it. Please help.

    Thanx in advance.

  2. #2
    Join Date
    Sep 2004
    Location
    Northeast, FL
    Posts
    332
    Here's a couple ideas. You could create an extra field in your datasource and insert the identity name into this field for each record, then set the DataNavigateUrlField property equal to the new field. Or you could look into templatecolumns, they provide enough flexibility to do this.

  3. #3
    Join Date
    Oct 2005
    Location
    NYC
    Posts
    108
    is this "DataNavigateUrlFormatString" for vs2005?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles