How can i bind Profile.property to datalist label?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lightwalker19
    New Member
    • Apr 2012
    • 22

    How can i bind Profile.property to datalist label?

    i have the property UserName and FullName. i am already returning The username like

    Code:
     <asp:Label ID="DeLabel" runat="server" Text='<%# Eval("De") %>' />
    But what i want is something like this

    Code:
     <asp:Label ID="DeLabel" runat="server" Text='<%# Eval(Profile.GetProfile("De").GetPropertyValue("FullName").ToString()) %>' />
    But the i get the error: "DataBindin g: 'System.Data.Da taRowView' does not contain a property with the name 'hello'."


    how can i achieve this? is there another way?
  • lightwalker19
    New Member
    • Apr 2012
    • 22

    #2
    Finally the solution!

    Create a helper Function(scalar )
    Code:
    CREATE FUNCTION [dbo].[GetProfilePropertyValue] (  
        @PropertyName as varchar(max)
        , @PropertyNamesString as varchar(max)
        , @PropertyValuesString as varchar(max)) 
    RETURNS varchar(max)
    AS
    BEGIN
        DECLARE @StartIndex int
        DECLARE @EndIndex int
        DECLARE @StartPos int
        DECLARE @Length int
        
        -- First we find the starting position
        Set @StartIndex = PatIndex('%' + @PropertyName + ':%', @PropertyNamesString) + LEN(RTRIM(@PropertyName)) + 3
        Set @EndIndex = PatIndex('%:%', Right(@PropertyNamesString, LEN(@PropertyNamesString) - @StartIndex))
        Set @StartPos = Cast(Substring(@PropertyNamesString, @StartIndex, @EndIndex) As Int)
        
        -- Now we need to know how long it is
        Set @StartIndex = @StartIndex + @EndIndex + 1
        Set @EndIndex = PatIndex('%:%', Right(@PropertyNamesString, LEN(@PropertyNamesString) - @StartIndex))
        Set @Length = Cast(Substring(@PropertyNamesString, @StartIndex, @EndIndex) As int)
        
        -- Now we get the value we want
        RETURN SUBSTRING(@PropertyValuesString, @StartPos + 1, @Length)
    END
    Here is the sql statement

    Code:
    SELECT Wall.De, Wall.Texto, Wall.Data, dbo.GetProfilePropertyValue('FullName', aspnet_Profile.PropertyNames, aspnet_Profile.PropertyValuesString) AS Expr1, Wall.Para FROM aspnet_Users INNER JOIN aspnet_Profile ON aspnet_Users.UserId = aspnet_Profile.UserId INNER JOIN Wall ON aspnet_Users.UserName = Wall.De WHERE (Wall.Para = @para)
    The parameters are
    Code:
    <asp:ProfileParameter Name="para" PropertyName="UserName" />
    Thank you :)

    Comment

    Working...