中继器似乎不具有DataItem属性的可见性? [英] Repeater doesn't seem to have visibility of DataItem's property?

查看:62
本文介绍了中继器似乎不具有DataItem属性的可见性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

因此,我遇到了一个严重麻烦的问题.我正在使用< asp:Repeater>在我的页面中并将其绑定到自定义类的集合.出于某种原因,转发器似乎可以毫无问题地绑定到我的类的"DisplayText"属性,但是当它尝试绑定到我的类的"NavigationUrl"属性时,会出现以下错误:

DataBinding: ''myNameSpace.helper'' does not contain a property with the name ''NavigationUrl''.

我不知道为什么这可能发生在一个财产而不发生在另一财产上.以下是一些代码段:

自定义类

Hello all!

So I am running into a seriously troublesome issue. I am using an <asp:Repeater> within my page and binding it to a collection of a custom class. For some reason the repeater seems to be able to bind to the "DisplayText" property of my class without a problem, but when it tries to bind to the "NavigationUrl" property of my class it gives me the following error:

DataBinding: ''myNameSpace.helper'' does not contain a property with the name ''NavigationUrl''.

I don''t have the faintest idea as to why this could be happening to one property without happening to the other. Here are some code snippets:

The custom class

public class helper
    {
        public string NavigationUrl, DisplayText;

        public helper(string inputUrl, string inputText)
        {
            NavigationUrl = inputUrl;
            DisplayText = inputText;
        }
    }



调用数据绑定的方法



The method that calls databinding

public void setData()
        {
            Collection<helper> dataToBind = pushDataIntoHelper(returnedData);

            if (dataToBind.Count() > 0)
            {
                rptrMerchandising.DataSource = dataToBind;
                rptrMerchandising.DataBind();
            }
        }



带有eval语句的转发器



The repeater with eval statements

<asp:Repeater ID="rptrMerchandising" runat="server">
    <ItemTemplate>
        <div class="suggestion">
            <a href='<%# Eval("NavigationUrl") %>'><%# Eval("DisplayText") %></a>
        </div>
    </ItemTemplate>
</asp:Repeater>



如果我将OnItemDataBound方法附加到转发器,然后将e.Item.FindControl与< asp:Hyperlink>控件而不是锚标记,我可以访问属性没有问题.似乎只有当我尝试在页面中对其进行评估时,我才没有可见性.

请让我知道您是否可以分享一些有关这里发生的事情的见解.如果我要在通过Eval语句填充和通过OnItemDataBound事件填充之间切换,那么此页面将非常糟糕. 先感谢您! :)



If I attach a OnItemDataBound method to the repeater and use e.Item.FindControl with an <asp:Hyperlink> control instead of an anchor tag I can access the properties no problem. It only seems that when I try to evaluate it in the page that I don''t have visibility.

Please let me know if you can share some insight as to what''s going on here. This page is going to be awfully sloppy if I''m switching between populating via Eval statements and populating via OnItemDataBound events ><<br mode="hold" />
Thank you in advance! :)

推荐答案

正如错误消息所述:DataBinding:"myNameSpace.helper"不包含名称为""NavigationUrl".

查看助手类,这也是非常正确的.
As the error message says: DataBinding: ''myNameSpace.helper'' does not contain a property with the name ''NavigationUrl''.

Looking at the helper class this is also very correct.
public class helper
    {
        public string NavigationUrl, DisplayText;
        public helper(string inputUrl, string inputText)
        {
            NavigationUrl = inputUrl;
            DisplayText = inputText;
        }
    }



您需要将NavigationUrl,DisplayText转换为属性,而不是公共变量.

祝您好运!



You need to convert NavigationUrl, DisplayText to properties instead of public variables.

Good luck!


最好的方法是尝试创建属性",而不仅仅是创建Public变量.

喜欢

Best way, try to create ''Properties'' instead of just creating Public variables.

Like

private string mNavigationUrl;
public string NavigationUrl
{
    get
    {
        return mNavigationUrl;
    }
    set
    {
        mNavigationUrl = value;
    }
}
private string mDisplayText;
public string DisplayText
{
    get
    {
        return mDisplayText;
    }
    set
    {
        mDisplayText = value;
    }
}


这篇关于中继器似乎不具有DataItem属性的可见性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆