GridView删除事件未获取gridview数据

时间:2011-12-26 21:09:53

标签: c# asp.net

这很简单,但我看不出我做错了什么。谁能发现这个问题?删除在gridview中不起作用。触发删除事件但未拾取数据。这是代码。

<asp:GridView ID="gvAdmins" runat="server" DataKeyField="UserId" Width="200px" DataSourceID="odsAdministratiors" 
  AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="5" GridLines="None"
  CellPadding="2" RowStyle-CssClass="gridview" AlternatingRowStyle-CssClass="altbgcolor" 
  OnRowDeleting="gvAdmins_OnDeleting" >
    <Columns>
      <asp:BoundField DataField="UserId" HeaderText="UserId" ReadOnly="True" Visible="false" />
      <asp:BoundField DataField="RoleId" HeaderText="RoleId" ReadOnly="True" Visible="false" />                                                
      <asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" Visible="false" />                                                
      <asp:BoundField DataField="altemail" HeaderText="altemail" ReadOnly="True" Visible="false" />
      <asp:TemplateField >
          <ItemTemplate>
             <asp:Label ID="lblFnane" runat="server" Text='<%# Bind("firstname") %>' /> 
             <asp:Label ID="lblLname" runat="server" Text='<%#  Bind("lastname")%>' />
          </ItemTemplate>
          <AlternatingItemTemplate>                                                 
            <asp:Label ID="lblFnane" runat="server" Text='<%# Bind("firstname") %>' /> 
            <asp:Label ID="lblLname" runat="server" Text='<%#  Bind("lastname")%>' />
          </AlternatingItemTemplate>
      </asp:TemplateField>
      <asp:CommandField ShowDeleteButton="true"    />
   </Columns>
</asp:GridView>

这是ods:

<asp:ObjectDataSource ID="odsAdministratiors" runat="server" 
    DeleteMethod="RemoveUsersFromRoles" InsertMethod="AddUserToRolesGroup" 
    OldValuesParameterFormatString="{0}" SelectMethod="GetAdmins" 
    TypeName="ManageAdminRoles" UpdateMethod="AddUserToRolesGroup" >
    <DeleteParameters>
        <asp:Parameter Name="firstname" Type="String" />
        <asp:Parameter Name="lastname" Type="String" />
        <asp:Parameter Name="Email" Type="String" />
        <asp:Parameter Name="altemail" Type="String" />
        <asp:Parameter Name="UserId" DbType="Guid" />
        <asp:Parameter Name="RoleId" DbType="Guid" />
        <asp:Parameter Name="RoleName" Type="String" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="firstname" Type="String" />
        <asp:Parameter Name="lastname" Type="String" />
        <asp:Parameter Name="Email" Type="String" />
        <asp:Parameter Name="altemail" Type="String" />
        <asp:Parameter Name="UserId" DbType="Guid" />
        <asp:Parameter Name="RoleId" DbType="Guid" />
        <asp:Parameter Name="RoleName" Type="String" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="firstname" Type="String" />
        <asp:Parameter Name="lastname" Type="String" />
        <asp:Parameter Name="Email" Type="String" />
        <asp:Parameter Name="altemail" Type="String" />
        <asp:Parameter DbType="Guid" Name="UserId" />
        <asp:Parameter DbType="Guid" Name="RoleId" />
        <asp:Parameter Name="RoleName" Type="String" />
    </UpdateParameters>
</asp:ObjectDataSource>

和bll方法:

private Get_Site_Admins_TableAdapter _Adapter = null;
protected Get_Site_Admins_TableAdapter Adapter
{
    get
    {
        if (_Adapter == null)
            _Adapter = new Get_Site_Admins_TableAdapter();
        return _Adapter;
    }
}

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public dsManageAdminRoles.Get_Site_AdminsDataTable GetAdmins()    
{
    try
    {
        return Adapter.GetAdminUsers();
    }
    catch (Exception ex) { throw ex; }
}


[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool RemoveUsersFromRoles(string firstname,string lastname,string Email,string altemail,Guid UserId,Guid RoleId,string RoleName)
{
    int rowsAffected = Adapter.Delete(firstname,lastname,Email,altemail,UserId,RoleId,RoleName);

    try
    {
        return rowsAffected == 1;
    }
    catch (Exception ex) { throw ex; }
}

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool AddUserToRolesGroup(string firstname, string lastname, string Email, string altemail, Guid UserId, Guid RoleId, string RoleName)
{
    int rowsAffected = Adapter.Insert(firstname, lastname, Email, altemail, UserId, RoleId, RoleName);

    try
    {
        return rowsAffected == 1;
    }
    catch (Exception ex) { throw ex; }
}

谢谢你的帮助。

Risho

1 个答案:

答案 0 :(得分:0)

跳出来的第一件事是你的某些gridview列可见=“false”,这有效地从该列中删除了数据绑定。通过将可见性更改为true进行测试,看看是否有帮助。你可以使用样式“display:none;”隐藏列但仍然有数据绑定。

其次,我在代码中看不到任何“gvAdmins_OnDeleting”事件。它存在吗?

HTH

戴夫