asp.net – 为什么页脚项目不包含在Repeater.Items中?
发布时间:2020-12-16 03:18:07 所属栏目:asp.Net 来源:网络整理
导读:我需要从按钮的OnClick事件中的FooterTemplate内的文本框中获取值.我的第一个想法是遍历我的转发器上的items-property,但正如您在此示例中所看到的,它只包含实际的数据绑定项,而不是页脚项. ASPX: asp:Repeater ID="Repeater1" runat="server" ItemTemplate
我需要从按钮的OnClick事件中的FooterTemplate内的文本框中获取值.我的第一个想法是遍历我的转发器上的items-property,但正如您在此示例中所看到的,它只包含实际的数据绑定项,而不是页脚项.
ASPX: <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> Item<br /> </ItemTemplate> <FooterTemplate> Footer<br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </FooterTemplate> </asp:Repeater> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 代码behind.cs: protected void Page_Load(object sender,EventArgs e) { ListItemCollection items = new ListItemCollection(); items.Add("value1"); items.Add("value2"); Repeater1.DataSource = items; Repeater1.DataBind(); } protected void Button1_Click(object sender,EventArgs e) { System.Diagnostics.Debug.WriteLine(Repeater1.Items.Count); } 此代码只输出“2”作为计数,那么如何在footertemplate中引用我的文本框? 解决方法
从
MSDN documentation开始,Items只是一组基于您绑定的DataSource的RepeaterItems,并且不包含Header或FooterTemplates中的项目.
如果要引用文本框,可以从转发器获取ItemDataBound事件的引用,您可以在其中测试页脚. 例如. private void Repeater_ItemDataBound(Object Sender,RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Footer) { TextBox textBox = e.Item.FindControl("TextBox1") as TextBox; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – Microsoft WebMatrix和Visual Studio有什么区别
- asp.net-mvc – 具有嵌套视图模型和Knockout的ASP.NET MVC
- asp.net-mvc-3 – 使用Ninject 2.2的MVC 3依赖注入将全局操
- 是否可以运行异步调用来在ASP.NET中设置会话?
- ASP.NET Core中实现用户登录验证的最低配置示例代码
- asp.net-mvc-3 – 当不需要/需要使用AntiForgeryToken时?
- Pro ASP.NET Core MVC(二)【第一个MVC 应用程序】
- asp.net-web-api – 如何设置Elmah与ASP.NET Web API
- Asp.Net中ajax+ashx使用详解
- asp.net – 不允许从数据类型sql_variant到uniqueidentifie
推荐文章
站长推荐
热点阅读