views:

42

answers:

2

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.

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 (e.g. <b>test</b> should show 'test' in bold) and each entry should be editable. 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.

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? 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?

+1  A: 

Hi,

You could also use a ListView - I tend to use this because its pretty robust. The data bound controls support the <%# Bind("Field") %> statement. 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). If you don't use a datasource control, you have to manually tap into the ItemEditing, ItemUpdating, etc. events.

Additionally, if you need to, you can get references to the controls using the current item's FindControl("ID") method.

HTH.

Brian
A: 

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.

Then place this control in the repeater and just give him an id to load and edit.

Aristos