views:

114

answers:

2
<asp:Repeater ID="rptrParent" runat="server">
<ItemTemplate>
        <li>
            <a href="<% =ResolveUrl("~/cPanel/UserView.aspx?User=")%><%# Eval("StudentUserName") %>">
                <span>
                    <%  ProfileCommon pc = new ProfileCommon();
                        pc.GetProfile(Eval("StudentUserName").ToString());
                        Response.Write(pc.FirstName + "" + pc.LastName);
                    %>
                </span>
            </a>
        </li>
</ItemTemplate>

The following error

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

is coming in this part

<%  ProfileCommon pc = new ProfileCommon();
    pc.GetProfile(Eval("StudentUserName").ToString());
    Response.Write(pc.FirstName + "" + pc.LastName);
%>
+3  A: 

In that context you need the full call like this:

<%#  Databinder.Eval(Container.DataItem,"StudentUserName") %>
Nick Craver
A: 

Alright guys, thanks for the help, but i got the solution :

<asp:Repeater ID="rptrParent" runat="server" onitemdatabound="rptrParent_ItemDataBound">
<ItemTemplate>
        <li>
            <a href="<% =ResolveUrl("~/cPanel/UserView.aspx?User=")%><%# Eval("StudentUserName") %>">
                <span>
                    <asp:Literal ID="lblUserName" runat="server"></asp:Literal>
                </span>
            </a>
        </li>
</ItemTemplate>

and in the code behind file, I wrote the following function :

protected void rptrParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item)
    {
        Literal UserName = e.Item.FindControl("lblUserName") as Literal;
        String uName = DataBinder.Eval(e.Item.DataItem, "StudentUserName").ToString();
        ProfileCommon pc = Profile.GetProfile(uName);
        UserName.Text = pc.FirstName + " " + pc.LastName + " [ " + uName + " ]";
    }
}
Sumit Sharma