[英]Edit items (hyperlinks) in a repeater with a single edit button
I've got a repeater which is bound to a List<> generated from an XML file. 我有一个转发器,该转发器绑定到从XML文件生成的List <>。 The file consists of two nodes, ID and Item.
该文件包含两个节点,ID和Item。
<Items><ID>0</ID>
<Item><![CDATA[<a target='blank' href="http://www.cnn.com">CNN News</a> ]]></Item>
I need to provide Edit functionality to allow a user to edit the url and the text of each item in the repeater. 我需要提供“编辑”功能,以允许用户编辑转发器中每个项目的url和文本。 I don't want separate Edit/Save buttons for each row;
我不希望每行都有单独的“编辑/保存”按钮; too much clutter.
太混乱了。 I guess that means a single Edit/Save button, which would essentially result in the XML file being "created" anew on each Save.
我想这意味着只有一个“编辑/保存”按钮,这实际上将导致在每个“保存”上重新“创建” XML文件。 Or, might there be a better way to do this?
或者,也许有更好的方法可以做到这一点?
I guess I'm asking two things: 我想我要问两件事:
A design suggestion on how to make a list of URLs editable (both url and text). 关于如何使URL列表(URL和文本)可编辑的设计建议。 Two separate text boxes I guess?
我猜两个单独的文本框?
How to handle edits. 如何处理编辑。
Thanks. 谢谢。
ItemTemplate
. ItemTemplate
可以有两个面板。 One for View and one for Edit . CommandArgument
, that when pressed, you set a Session variable with the ID of the item clicked. CommandArgument
,在按下该按钮时,您可以设置一个带有单击的项目ID的Session变量。 Then when you rebind your repeater, you check each item's ID against the Session edit ID variable. I've used this method numerous times and it works great! 我已经多次使用这种方法,并且效果很好!
If you need any code to illustrate any of the point above, feel free to ask. 如果您需要任何代码来说明以上几点,请随时询问。
As a side not, your XML looks a little strange. 顺便说一句,您的XML看起来有些奇怪。 There doesn't seem to be a parent node to represent each URL/ID pair.
似乎没有一个父节点代表每个URL / ID对。 It this an oversight, a typo, or am I missing something here?
这是一个疏忽,还是一个错字,还是我在这里错过了一些东西?
EDIT: 编辑:
This is a good way to utilize ViewState in your scenario: 这是在您的方案中利用ViewState的好方法:
private enum PageStates
{
None = 0,
View = 1,
Edit = 2
}
/// <summary>
/// The current state of the page
/// </summary>
private PageStates PageState
{
get
{
if (ViewState["PageState"] == null)
ViewState["PageState"] = PageStates.View; //default to view state
return (PageStates)ViewState["PageState"];
}
set
{
ViewState["PageState"] = value;
}
}
By encapsulating ViewState access in a property, any changes to the method of storing the variable (Session, DB, etc) are abstracted away from any code that accesses it. 通过将ViewState访问封装在一个属性中,对存储该变量的方法(会话,数据库等)的任何更改都将从访问它的任何代码中抽象出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.