2013-02-24 98 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

相关问题