ASP.Net repeater item.DataItem为null
发布时间:2020-12-16 07:31:31 所属栏目:asp.Net 来源:网络整理
导读:在网页中,在加载时,我用两个表填充数据集,其中包含这些表之间的关系,然后将数据加载到具有嵌套转发器的转发器中.用户单击按钮后也会发生这种情况.数据从SQL数据库加载,并且在回发后将转发器数据源设置为数据集.但是,当ItemDataBound发生时,Item.Dataitem始终
在网页中,在加载时,我用两个表填充数据集,其中包含这些表之间的关系,然后将数据加载到具有嵌套转发器的转发器中.用户单击按钮后也会发生这种情况.数据从SQL数据库加载,并且在回发后将转发器数据源设置为数据集.但是,当ItemDataBound发生时,Item.Dataitem始终为null.
为什么会这样? 这是数据绑定代码: this.rptCustomSpaList.DataSource = ds; this.rptCustomSpaList.DataBind(); 这是ItemDataBound代码: RepeaterItem item = e.Item; Repeater ChildRepeater = (Repeater)item.FindControl("rptCustomSpaItem"); DataRowView dv = e.Item.DataItem as DataRowView; ChildRepeater.DataSource = dv.CreateChildView("sparelation"); ChildRepeater.DataBind(); 下面是我的HTML转发器代码 <asp:Repeater ID="rptCustomSpaList" runat="server" onitemdatabound="rptCustomSpaList_ItemDataBound"> <HeaderTemplate></HeaderTemplate> <ItemTemplate> <table> <tr> <td><asp:Label ID="Label3" runat="server" Text="Spa Series:"></asp:Label></td> <td><asp:Label ID="Label4" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SPASERIESVALUE") %>'></asp:Label></td> </tr> <tr> <td><asp:Label ID="Label5" runat="server" Text="Spa Model:"></asp:Label></td> <td><asp:Label ID="Label6" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SPAMODELVALUE") %>'></asp:Label></td> </tr> <tr> <td><asp:Label ID="Label9" runat="server" Text="Acrylic Color:"></asp:Label></td> <td><asp:Label ID="Label10" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ACRYLICCOLORVALUE") %>'></asp:Label></td> </tr> <tr> <td> <asp:Label ID="Label11" runat="server" Text="Cabinet Color:"></asp:Label> </td> <td> <asp:Label ID="Label12" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CABPANCOLORVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label17" runat="server" Text="Cabinet Type:"></asp:Label> </td> <td> <asp:Label ID="Label18" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CABINETVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label13" runat="server" Text="Cover Color:"></asp:Label> </td> <td> <asp:Label ID="Label14" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"COVERCOLORVALUE") %>'></asp:Label> </td> </tr> </table> <asp:Label ID="Label15" runat="server" Text="Options:"></asp:Label> <asp:Repeater ID="rptCustomSpaItem" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"PROPERTY") %>'></asp:Label> </td> <td> <asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"VALUE") %>'></asp:Label> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <table> <tr> <td style="padding-top:15px;padding-bottom:30px;"> <asp:Label ID="Label7" runat="server" Text="Configured Price:"></asp:Label> </td> <td style="padding-top:15px;padding-bottom:30px;"> <asp:Label ID="Label8" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SPAVALUEVALUE") %>'></asp:Label> </td> </tr> </table> <asp:Label ID="Label16" runat="server" Text="------"></asp:Label> </ItemTemplate> <FooterTemplate></FooterTemplate> </asp:Repeater> 解决方法
是的,DataItem总是空的吗?因为您可能只需要在访问DataItem属性之前检查
ItemType属性:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { var data = e.Item.DataItem; // .... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp-classic – 经典asp运行的用户是什么?
- asp.net-web-api – Web Api:找不到System.Net.Http版本2.
- asp.net – 在jQuery中捕获异常
- asp.net-mvc – ASP.NET MVC ActionResult背后的推理是一个
- asp.net – 插入多行的最佳方式(ADO.NET)
- asp.net-mvc – 我应该让MVC处理我的favicon请求吗?
- ASP.NET变量范围
- asp.net-mvc-3 – asp.net mvc会话经常在托管环境中过期
- asp.net – 具有2个不同域的mvc3路由
- asp.net-mvc – 将隐藏文本字段附加到表单MVC
推荐文章
站长推荐
- asp.net – App Settings和connectionStrings配置
- asp.net – 自定义日期colmn telerik网格的过滤器
- ASP.NET——总结
- 如何在服务器端缓存ASP.NET自定义HttpHandler响应
- asp.net – ViewState vs cookies vs cashing vs
- asp.net – Page.PreLoad事件未出现在visual stu
- asp.net-web-api – 首先使用ASP.NET Web API的E
- asp.net-mvc – Internet Explorer缓存asp.netmv
- 体系结构设计良好的ASP.NET WebForms站点示例
- asp.net-mvc – ASP.NET MVC – HtmlHelper和Ses
热点阅读