开发者

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

开发者 https://www.devze.com 2022-12-25 07:15 出处:网络
I am getting the following error Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

I am getting the following error

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

but all I am trying to do is inside a ASP.NET REPEATER Control

<% if ( Eval("Message").ToString() == HttpContext.Current.Profile.UserName) %>
<% { %>

           <asp:ImageButton runat="ser开发者_如何学JAVAver" etc.... />
<% } %>


The syntax is

<%# Eval("...") %>

You could do something like

<asp:ImageButton Visible='<%# ShowImg(Eval(Container.DataItem,"Message")) %>' />

and in your codebehind:

boolean ShowImg(string msg)
{
     return (msg == HttpContext.Current.Profile.UserName);
}


An alternative is this:

<asp:ImageButton runat="server" Visible='<%# Eval("Message").ToString() == HttpContext.Current.Profile.UserName %>' />

Then there is no need for code behind.


Its too late but i would like to answer it in my way, what i used to achieve it:

<%# Eval("Message").toString()== HttpContext.Current.Profile.UserName)?"<asp:ImageButton runat="server" etc.... />" :""%>

Now this will only show image button if Message is equal to username.

This might help any one else in same situation.

In my situation i needed to check null and empty string...so i implemented like this below:

<%# Eval("DateString")!= null && Eval("DateString")!= ""? "<span class='date'>"+Eval("DateString") + "</span>":"" %>

Thanks


Another way to implement it:

public string nonImage() {
    string imgTag = "", Article_OwnerID = "", Article_ID = "", Article_OwnerType = "", imgSrc = "";
    DataTable DtArticles = SE_Article.GetArticlesList(UserID, UserID, ProfileType, CounterOfPage, CountPerPage, (short) SE_Action.OwnerType.user, SE_Security.CheckInjection(TxtSearch.Text.Trim()), CategoryID, "all_articles", DrpOrderBy.SelectedValue, DrpSort.SelectedValue);
    if (DtArticles != null && DtArticles.Rows.Count > 0) {
        Article_OwnerID = DtArticles.Rows[0]["Article_OwnerID"].ToString();
        Article_ID = DtArticles.Rows[0]["Article_ID"].ToString();
        Article_OwnerType = DtArticles.Rows[0]["Article_OwnerType"].ToString();
    }
    if (SE_Article.GetArticleCover(Convert.ToInt32(Article_OwnerID), Convert.ToInt32(Article_ID), Convert.ToInt16(Article_OwnerType)) != System.Configuration.ConfigurationManager.AppSettings["NoPhotoArticleThumb"]) {
        imgSrc = SE_Article.GetArticleCover(Convert.ToInt32(Article_OwnerID), Convert.ToInt32(Article_ID), Convert.ToInt16(Article_OwnerType));
        imgTag = "<img class='img_article_cover' src='" + imgSrc + "' alt='مقاله" + Article_ID + "' />";
    }
    return imgTag;
 }


 <% nonImage(); %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号