开发者

How can I make a repeater field editable?

I have a page with a repeater.. I have to make some fields of this one editable. I don't see how I can transform the repeater label into a textbox.. Can I use jquery to do that?

开发者_开发百科Have somebody make this kind of manipulation?

Thanks..


The Repeater control does not have an EditTemplate like many of the other data controls.

I would suggest having the edit fields either in a hidden Placeholder, then show this when clicking an edit button. This would involve the page posting back and then you having to show/hide the relevant parts in the ItemCommand handler.

Another way would be do add the edit fields/textboxs in a Panel control, then hide this through display: none;. Then you can change this to display: block; with some javascript. This will avoid the page PostBack.


This can be done in a Repeater, but a DataList control is more straightforward and is just as easy to use. There's an MSDN article on doing it in a Datalist control with full source code here: http://msdn.microsoft.com/en-us/library/bf5211wb(v=vs.71).aspx

Converting a repeater to a DataList is a much easier approach than having editable items in a Repeater.

HOWEVER

to answer your question directly, there IS a Codeproject sample here: http://www.codeproject.com/KB/aspnet/EditableRepeater.aspx

that shows how to use a Repeater with full edit functionality (including adding and deleting items).

To see the relevant code in the CodePlex article, search for the text "EditIndex". The relevant code-behind is always a few lines above and/or below this keyword.


It depends on how you want to do this:

  1. using standart control probably you need GridView.

  2. You can define the template for repeater and put TextBox there, then on postback you will need to find dynamically created controls and also you will need to take care to keep ID's of these controls the same on postbacks.

  3. And the other thing - you can replace label with the textBox using jQuery and then update value via Ajax reques.

You decide what you need :) Anyway it's a lot of samples in the internet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜