如何在代码后面以编程方式创建ASP.NET转发器控件 [英] How to create ASP.NET repeater control programatically in code behind

查看:57
本文介绍了如何在代码后面以编程方式创建ASP.NET转发器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在代码后面而不是在设计页面中创建这个转发器,即aspx。因为我已经创建了bootstrap 4.1.3版本选项卡面板。此选项卡面板在代码后面而不是在设计模式下创建。这个转发器应该调用一个标签内容,所以如何实现这个目标请任何人解释我先生



我尝试过:



I want to create this repeater in code behind not in design page i.e, aspx. Because i have created bootstrap 4.1.3 version tab-panel. This tab-panel is created in code behind not in design mode. This repeater should call in one of the tab-content so how to achieve this target please anybody explain me sir

What I have tried:

Repeater RptrQuestionsAndOptions = new Repeater();                
foreach (RepeaterItem item in RptrQuestionsAndOptions.Items)
{
    headeritem = new RepeaterItem(item.ItemIndex, ListItemType.Header);
    itemtemplate = new RepeaterItem(item.ItemIndex, ListItemType.Item);
    footeritem = new RepeaterItem(item.ItemIndex, ListItemType.Footer);
}
HtmlTable table = new HtmlTable();
table.Style["min-height"] = "300px";
table.Style["width"] = "100%";
headeritem.Controls.Add(table);



headeritem是全局声明的。

在后面的代码中创建转发器时出错它不是创建headeritem。错误发生在foreach循环中。我现在必须做些什么来减少错误并实现我的目标。请帮助任何人解决此问题


headeritem is declared globally.
Getting error when creating repeater in code behind that it is not creating headeritem. The error is at foreach loop. What i have to do now to reduce that error and achieve my goal. Please help anyone to solve this

推荐答案

您首先需要了解Web的无状态特性,然后了解如何使用动态控件。您可以使用谷歌或使用您首选的搜索引擎在网络中查找这些信息。这是一篇很好的文章:无限循环 - 真正理解动态控制(第1部分) [ ^ ]



要开始使用动态ASP.NET Web Controls生成,我建议你从这里开始:如何:动态创建ASP.NET Web服务器控件模板 [ ^ ]
You need to understand first how the stateless nature of web works and then understand how to work with dynamic controls. You can use google or use your preferred search engine to find those information in the net. Here's one good article to start with: Infinities Loop - TRULY Understanding Dynamic Controls (Part 1)[^]

To get started working with dynamic ASP.NET Web Controls generation, I'd suggest you to start here: How To: Create ASP.NET Web Server Control Templates Dynamically[^]


这篇关于如何在代码后面以编程方式创建ASP.NET转发器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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