数据绑定方法(例如 Eval()、XPath() 和 Bind())只能在数据绑定控件的上下文中使用

发布于 2024-08-27 23:19:59 字数 338 浏览 4 评论 0原文

我收到以下错误

Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。

但我想做的只是在 ASP.NET REPEATER 控件内

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

           <asp:ImageButton runat="server" etc.... />
<% } %>

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="server" etc.... />
<% } %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝不放开 2024-09-03 23:19:59

语法是

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

执行类似and 的操作:

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

您可以在代码隐藏中

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

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);
}
初与友歌 2024-09-03 23:19:59

另一种选择是:

<asp:ImageButton runat="server" Visible='<%# Eval("Message").ToString() == 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.

流心雨 2024-09-03 23:19:59

为时已晚,但我想以我的方式回答它,我用什么来实现它:

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

现在,如果消息等于用户名,则只会显示图像按钮。

这可能会对处于相同情况的其他人有所帮助。

在我的情况下,我需要检查 null 和空字符串...所以我实现如下:

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

谢谢

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

别忘他 2024-09-03 23:19:59

另一种实现方式:

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(); %>

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(); %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文