2013-02-24 97 views
0

我在一段時間內沒有使用formview,這種方式並不是普通的,它不使用ObjectDataSource,而是使用BLL類進行CRUD操作。它不更新。有人可以看看這個,並指出顯而易見的?當使用BLL和DAL時,FormView不會更新

其實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; 
    } 
} 

回答

0

如果禁用ViewState的(你顯然沒有),你必須重新綁定與上回發的數據完全相同的數據綁定控件,以便它可以重現相同的狀態前,其事件實際上可以觸發(在你的情況下update_Click)。

這裏沒有看到你的數據綁定代碼,這只是一個黑暗中的鏡頭,但我想你不會重新控制Postback或使用(稍微)不同的數據重新綁定它,這會導致你的事件不被解僱。

啓用ViewState或,如果您不想要,請確保您的數據綁定在Postback上正確發生。如果這沒有幫助,請提供代碼綁定FormView的地方。

+0

不知道有關formview的很多內容,我添加了一個ItemTemplate,其編輯模板的設置相同,並突然生效。 – Risho 2013-02-25 18:00:58

相關問題