评估和演示与数据字段在ASP:Datagrid的 [英] Eval versus DataField in ASP:Datagrid

查看:107
本文介绍了评估和演示与数据字段在ASP:Datagrid的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被窃听我这真的是随机的问题。它工作在一天结束的时候,但这个问题花了一些时间来弄清楚,想知道为什么会这样,所以如果有人流下了关于这个问题,我将非常感激的一些情况。这里的问题

I have this really random problem with is bugging me. It works at the end of the day but the problem took some time to figure out and was wondering why this happens so if anyone shed some light on the subject I would be really grateful. Here is the problem

我有我的DataGrid中的以下两列

I have the following two columns on my datagrid

<asp:boundcolumn
datafield="contentsection.Id"
headerstyle-cssclass="dgHead"
headertext="Section"
itemstyle-cssclass="dgItem" />

<asp:templatecolumn>
<itemtemplate><%#Eval("contentsection.Id") %></itemtemplate>
</asp:templatecolumn>

第一列给我的错误:

The first column gives me the error of:

字段或属性名称为contentsection.Id没有选择的数据源上找到

但第二次上运行正常。任何思想或理论,为什么发生这种情况?

but the second on runs fine. Any ideas or theories as to why this is happening ?

这是我打电话,我绑定数据的方式是像这样:

The way that I call and bind my data is like so:

页面加载code背后

ContentList.DataSource = ContentBlockManager.GetList();
ContentList.DataBind();

这是超载,默认情况下的GetList()函数传递一个0

The GetList() function it is overloaded and by default passed a 0

public static List<ContentBlockMini> GetList(int SectionId)
{
    List<ContentBlockMini> myList = null;

    SqlParameter[] parameters = { new SqlParameter("@ContentSectionId", SectionId) };

    using (DataTableReader DataReader = DataAccess.GetDataTableReader("dbo.contentblock_get", parameters))
    {
        if (DataReader.HasRows)
        {
            myList = new List<ContentBlockMini>();
        }
        while (DataReader.Read())
        {
            myList.Add(FillMiniDataRecord(DataReader));
        }
    }

    return myList;
}

和我的数据记录的灌装。该ContentSection是另一个对象,它是内文对象的属性。

and my filling of the data record. The ContentSection is another Object Which is a property of the ContentBlock object

private static ContentBlockMini FillMiniDataRecord(IDataRecord DataRecord)
        {
            ContentBlockMini contentblock = new ContentBlockMini();

            contentblock.Id = DataRecord.GetInt32(DataRecord.GetOrdinal("Id"));
            contentblock.Name = DataRecord.GetString(DataRecord.GetOrdinal("Name"));
            contentblock.SEOKeywords = DataRecord.IsDBNull(DataRecord.GetOrdinal("SEOKeywords")) ? string.Empty : DataRecord.GetString(DataRecord.GetOrdinal("SEOKeywords"));
            contentblock.SEODescription = DataRecord.IsDBNull(DataRecord.GetOrdinal("SEODescription")) ? string.Empty : DataRecord.GetString(DataRecord.GetOrdinal("SEODescription"));
            if (DataRecord.GetInt32(DataRecord.GetOrdinal("ContentSectionId")) > 0)
            {
                ContentSection cs = new ContentSection();
                cs.Id = DataRecord.GetInt32(DataRecord.GetOrdinal("ContentSectionId"));
                cs.Name = DataRecord.IsDBNull(DataRecord.GetOrdinal("ContentSectionName")) ? string.Empty : DataRecord.GetString(DataRecord.GetOrdinal("ContentSectionName"));
                contentblock.contentsection = cs;

            }
            return contentblock;
        }

你去那里是pretty大部分的开始到结束。

There you go that is pretty much the start to end.

推荐答案

在绑定标记是一个双向绑定,并使用连接到该对象的数据源的默认命名空间。这不能被覆盖,而且因为这种紧耦合连接的命名空间应该不放过作为假设(因为它是动态地从数据源拉)。

The "Bind" marker is a two-way bind and is made using the default namespace attached to the datasource of the object. This can't be overridden, and because of this tightly coupled connection the namespace should be left off as assumed (since it's dynamically pulled from the datasource).

评估是有约束力的单向的,可以与该会履行一个正确的评价任何名称空间中使用。日期,字符串,方法调用等,在您的示例中提供的空间只是提供的eval对哪里得到相关数据的标记。

Eval is a one-way binding that can be used with any namespace that will fulfill a proper evaluation. Dates, strings, method calls, etc. The namespace provided in your example just provides eval with a marker on where to get the data relevant.

这里的关键是结合的性质。 EVAL是一种射后不理之类的结合,其中的绑定是比较刚性的,以促进双向。

The key here is the nature of the binding. Eval is a "fire and forget" sort of binding where as Bind is more rigid to facilitate the two-way.

这篇关于评估和演示与数据字段在ASP:Datagrid的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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