无法从 ListView 的 ItemTemplate 填充更新参数
我正在使用 ListView,并希望在客户端实现 ListView 项目从只读模式到编辑模式的切换。其中一些讨论在:客户端内联表单编辑
我正在尝试通过以下方法来做到这一点:
<asp:ListView ID="ListViewContactNumber" runat="server">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<div class="readonly">
<asp:Label ID="LabelType" runat="server"
Text='<%# Server.HtmlEncode(Eval("Name").ToString()) %>'></asp:Label>
<a href="#" onclick="switchState(this,"edit");return false;">Edit</a>
</div>
<div class="edit">
<asp:TextBox ID="TextBoxName" runat="server"
Text='<%# Eval("Name") %>'
MaxLength="256"
Columns="10"></asp:TextBox>
<asp:LinkButton ID="LinkButtonSave" runat="server"
Text="Save"
OnClick="LinkButtonSave_Click"></asp:LinkButton>
<a href="#" onclick="switchState(this,"readonly");return false;">Cancel</a>
</div>
</ItemTemplate>
</asp:ListView>
switchState
是一个 Javascript 函数,它只是隐藏/显示带有 readonly 和 edit< 的 DIV
/em> 类名。在 LinkButtonSave_Click
中,我从 TexBoxName
获取值,但它始终包含绑定的原始值,而不是在文本框中输入的编辑值。
- ASP.NET 不回发文本框值是因为它位于 ItemTemplate 中,还是其他原因导致了此问题?
- 我可以使用中继器来完成此任务吗?
I am using a ListView and would like to implement the switch from read only mode to edit mode for a ListView item on the client side. Some of this is discussed at: Inline form editing on client side
I am trying to do this by something like:
<asp:ListView ID="ListViewContactNumber" runat="server">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<div class="readonly">
<asp:Label ID="LabelType" runat="server"
Text='<%# Server.HtmlEncode(Eval("Name").ToString()) %>'></asp:Label>
<a href="#" onclick="switchState(this,"edit");return false;">Edit</a>
</div>
<div class="edit">
<asp:TextBox ID="TextBoxName" runat="server"
Text='<%# Eval("Name") %>'
MaxLength="256"
Columns="10"></asp:TextBox>
<asp:LinkButton ID="LinkButtonSave" runat="server"
Text="Save"
OnClick="LinkButtonSave_Click"></asp:LinkButton>
<a href="#" onclick="switchState(this,"readonly");return false;">Cancel</a>
</div>
</ItemTemplate>
</asp:ListView>
switchState
is a Javascript function that simply hides/shows the DIV
s with the readonly and edit classnames. In LinkButtonSave_Click
I get the value from TexBoxName
but it always contains the bound original value and not the edited value that was entered in the texbox.
- Does ASP.NET not postback the textbox value because it is in the ItemTemplate or is it something else that's causing this problem?
- Could I use a Repeater instead to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当使用 javascript 更改状态时,您必须使用 ajax 来更新数据::
when using javascript to change state you must use ajax to update your data ::
事实证明ListView根本不是问题的根源。我在 Page_Load 上重新进行数据绑定,而没有检查它是否是回发。
It turned out that the ListView was not the source of the problem at all. I was re-databinding on Page_Load without checking if it was a postback.