我已经有一段时间没有使用 formview 了,这个并不普通,它不使用 ObjectDataSource,而是使用 BLL 类进行 CRUD 操作。它不更新。有人可以看看这个并指出显而易见的吗?
实际上 update_Click 方法永远不会触发。我也尝试过添加一个 onupdating 事件,但这也确实触发了。
<asp:FormView ID="fvContactDetails_Mod" runat="server" DataKeyNames="memberid" EnableViewState="false"
OnDataBound="fvContactDetails_Mod_OnDataBound" >
<EditItemTemplate>
<table>
<tr>
<td class="formlabel"><label for="fname">First Name:</label></td>
<td class="formvalue">
<asp:TextBox runat="server" ID="txtFname" CssClass="txtfield" text='<%# Bind("firstname") %>' />
<asp:RequiredFieldValidator ControlToValidate="txtFname" ErrorMessage="First Name is required." ID="RequiredFieldValidator3" runat="server" ToolTip="First Name is required." ValidationGroup="CreateUserForm">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="formlabel"><label for="lname">Last Name:</label></td>
<td class="formvalue">
<asp:TextBox runat="server" ID="txtLname" CssClass="txtfield" text='<%# Bind("lastname") %>'/>
<asp:RequiredFieldValidator ControlToValidate="txtLname" ErrorMessage="Last Name is required." ID="RequiredFieldValidator4" runat="server" ToolTip="Last Name is required." ValidationGroup="CreateUserForm">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<p><Club:RolloverButton ID="update" runat="server" Text="Update Registration" OnClick="update_Click" /></p>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView
protected void update_Click(object sender, FormViewUpdateEventArgs e)
{
MembershipUser user = Membership.GetUser();
try
{
TextBox txtFname = (TextBox)fvContactDetails_Mod.FindControl("txtFname");
TextBox txtLname = (TextBox)fvContactDetails_Mod.FindControl("txtLname");
DropDownList ddlRankid = (DropDownList)fvContactDetails_Mod.FindControl("ddlRankid");
MemberInformation update = new MemberInformation();
if (update.UpdateMemberInfo((Guid)user.ProviderUserKey,
txtFname.Text,
txtLname.Text,))
{
ContactStatus.Text = "Details have been updated sucessfully.";
ContactStatus.ControlStyle.ForeColor = Color.Blue;
}
}
catch (Exception ex)
{
ContactStatus.Text = "Error updating contact details: " + ex.Message;
ContactStatus.ControlStyle.ForeColor = Color.Red;
}
}