English 中文(简体)
为什么数据系统在“Loadhandler”页中永远无效?
原标题:Why is DataItem always null in the Page_Load handler?

I ve created an ASP.net web page with an ASP Repeater. I bind the ASP Repeater with an IOrderedEnumerable<int> DataSource.

我需要从“Load”事件手稿中查阅Repoter数据系统。 然而,当我试图获得<编码>repeater.Items[x]的价值时。 数据,我永远无效。 这里应始终具有分类价值。

尽管如此,该网页还是罚款。 为什么我能够进入“Load事件手稿”页内我的“动脉”财产?

问题回答

页: 1 请参阅<代码>Repeater。 项目[i]。 缩略语 手稿,试图提早加入Repeater,首先:

repeater.DataBind()

只有在数据具有约束力时才能获得。

正如其他人所说的那样,它只是在数据具有约束力时才能得到。 您将需要对复读者的“OnItemDataBound”活动进行跟踪。 如果是手,你可以这样做:

protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    switch (e.Item.ItemType)
    {
        case ListItemType.Item:
        case ListItemType.AlternatingItem:
            WhateverType Item = e.Item.DataItem as WhateverType;
            break;
    }
}

数据项目只在数据约束程序完成后才存在。 复数中唯一保存的就是控制特性。 如果你需要这些项目中的数据,你可以像早些时说过的假装数据,或者如果不可能的话,你可以写出一个使用功能,即重复数据项目,并从你的重复控制中提取数据(假设你储存了这些控制中所需要的所有信息)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签