简体   繁体   English

我应该使用中继器吗?

[英]Should I use a repeater?

I have a table similar to: 我有一个类似于以下表格:

ID...NAME.....HTMLTEXT
1....Footer....`<b>test</b>`

where each entry has some HTML text and an associated Name and ID. 其中每个条目都有一些HTML文本以及关联的名称和ID。

What I want to do in ASP.net C# is to list each of these entries on a page in such a way that the HTML text should be displayed exactly how it is meant to be (eg <b>test</b> should show 'test' in bold) and each entry should be editable. 我想在ASP.net C#中做的就是以这样一种方式列出页面上的每个条目,使得HTML文本应准确显示其含义(例如,应显示<b>test</b> “测试”(粗体),并且每个条目都应可编辑。 When the Edit button is clicked on an entry, the HTML text should be replaced by a textbox with the text inside it so that you can edit it and save it. 单击条目上的“编辑”按钮时,应将HTML文本替换为文本框,并在其中包含文本,以便您可以对其进行编辑和保存。

For example: 例如:

FOOTER --EditButton-- 脚-编辑按钮-

TEXT test 文字测试

Now I am not sure on what is the best way to do this. 现在,我不确定什么是最好的方法。 Should I use a repeater with an ItemTemplate for each entry? 我应该为每个条目使用带有ItemTemplate的中继器吗? If I use a repeater, and an edit button is clicked, how do I know which edit button is clicked and how do I know which textbox to display the text etc? 如果我使用中继器,并且单击了编辑按钮,如何知道单击了哪个编辑按钮以及如何知道要显示文本的文本框等?

You could also use a ListView - I tend to use this because its pretty robust. 您也可以使用ListView-我倾向于使用它,因为它非常健壮。 The data bound controls support the <%# Bind("Field") %> statement. 数据绑定控件支持<%#Bind(“ Field”)%>语句。 You setup your templates in ItemTemplate or EditItemTemplate, and if you add the proper commands to the buttons in the UI, it all wires up the proper events for you (depending on how you data bind). 您可以在ItemTemplate或EditItemTemplate中设置模板,并且如果将适当的命令添加到UI中的按钮,则它们都会为您连接适当的事件(取决于数据绑定的方式)。 If you don't use a datasource control, you have to manually tap into the ItemEditing, ItemUpdating, etc. events. 如果不使用数据源控件,则必须手动点击ItemEditing,ItemUpdating等事件。

Additionally, if you need to, you can get references to the controls using the current item's FindControl("ID") method. 此外,如果需要,可以使用当前项目的FindControl(“ ID”)方法获取对控件的引用。

HTH. HTH。

Create a custom control (.ascx) and on this control make the line with the view that you wish, and handle the change/save/delete etc. 创建一个自定义控件(.ascx),并在此控件上以所需的视图对齐,并处理更改/保存/删除等。

Then place this control in the repeater and just give him an id to load and edit. 然后将此控件放在转发器中,并给他一个ID以进行加载和编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM