Can't populate update parameters from a ListView's 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>
开发者_Python百科 <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?
when using javascript to change state you must use ajax to update your data ::
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.
精彩评论