2012-10-29 2 views
1

어떤 이유로 행이 삭제 된 후 Gridview가 자동으로 새로 고쳐지지 않습니다. 코드를 debbuging 할 때 UserAccessGrid_RowDeleted 메서드에 도달하지만 아무 것도 페이지에서 발생하지 않습니다. 여기 내 코드가있다. 뒤에AJAX UpdatePanel 내의 GridView가 삭제시 새로 고침되지 않습니다.

<ajax:UpdatePanel ID="UserAccessGridUpdatePanel" runat="server" RenderMode="Inline" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:GridView ID="UserAccessGrid" runat="server" DataKeyNames="UserID" AutoGenerateColumns="False" OnRowDeleting="UserAccessGrid_RowDeleting" OnRowDeleted="UserAccessGrid_RowDeleted" 
      CellPadding="3" Width="100%"> 
      <RowStyle CssClass="GridRow" /> 
      <AlternatingRowStyle CssClass="GridAltRow" /> 
      <HeaderStyle HorizontalAlign="Left" /> 
      <Columns>  
       <asp:TemplateField> 
        <ItemTemplate> 
         <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this user?');"></asp:LinkButton> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Employee Name"> 
        <ItemTemplate> 
         <a href="AddUser.aspx?uid=<%# QueryStringEncryption.Encrypt(DataBinder.Eval(Container.DataItem, "UserID").ToString())%>"> 
          <%#DataBinder.Eval(Container.DataItem, "EmployeeName") %> 
         </a> 
        </ItemTemplate>       
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Email"> 
        <ItemTemplate> 
         <%#DataBinder.Eval(Container.DataItem, "EmailAddress")%> 
        </ItemTemplate>       
       </asp:TemplateField> 
       <asp:CheckBoxField 
        DataField="IsCSEAdmin" 
        HeaderText="CSE Administrator" 
        ReadOnly="True" 
        ItemStyle-HorizontalAlign="Center" > 
       <ItemStyle HorizontalAlign="Center" /> 
       </asp:CheckBoxField> 
       <asp:CheckBoxField 
        DataField="IsAdmin" 
        HeaderText="Country Administrator" 
        ReadOnly="True" 
        ItemStyle-HorizontalAlign="Center" > 
       <ItemStyle HorizontalAlign="Center" /> 
       </asp:CheckBoxField> 
      </Columns> 
     </asp:GridView> 
    </ContentTemplate> 
    <Triggers> 
     <ajax:AsyncPostBackTrigger ControlID="UserAccessGrid" /> 
    </Triggers> 
</ajax:UpdatePanel> 

코드 :

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!(Master.user.IsAdmin || Master.user.IsCSEAdmin)) 
     Response.Redirect("Unauthorized.aspx"); 

    //UserAccessDS.SelectParameters["UserID"].DefaultValue = Master.user.UserID; 
    if (!Page.IsPostBack) 
    { 
     UserAccessGridBind(); 
    } 
} 

protected void UserAccessGrid_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{ 
    int UserID = (int)UserAccessGrid.DataKeys[e.RowIndex].Value; 
    if (Convert.ToInt32(Master.user.UserID) == UserID) 
    { 
     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert", "alert('Delete action permitted on that user!');", true); 
    } 
    else 
    { 
     OleDbCommand command = new OleDbCommand("dbo.usp_DeleteUserbyUserID", Master.connection); 
     command.Connection.Open(); 

     try 
     { 
      command.CommandType = CommandType.StoredProcedure; 
      OleDbParameter param = command.Parameters.Add("@UserID", OleDbType.Integer); 
      param.Value = UserID; 

      command.ExecuteNonQuery(); 

      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Information", "alert('Delete complete.');", true); 
     } 
     catch (Exception ex) 
     { 
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert", "alert('An error occured : " + ex.Message + "');", true); 
     } 
     finally 
     { 
      command.Connection.Close(); 
     } 
    } 
} 

protected void UserAccessGrid_RowDeleted(object sender, GridViewDeletedEventArgs e) 
{ 
    UserAccessGridUpdatePanel.Update(); 
} 

private void UserAccessGridBind() 
{ 
    int UserID = Convert.ToInt32(Master.user.UserID); 

    OleDbDataAdapter adapter = new OleDbDataAdapter(); 
    OleDbCommand command = new OleDbCommand("dbo.usp_GetAccessListByUserID", Master.connection); 

    command.CommandType = CommandType.StoredProcedure; 
    command.Parameters.AddWithValue("UserID", UserID); 

    adapter.SelectCommand = command; 

    DataSet UserAccess = new DataSet(); 
    adapter.Fill(UserAccess); 

    UserAccessGrid.DataSource = UserAccess; 
    UserAccessGrid.DataBind(); 
} 

답변

0

당신은 후에 다시 그리드를 결합 삭제해야합니다. 당신이 일찍 묶었을 때.

레코드 삭제 후 표를 새로 고치려면 UserAccessGridBind() 메서드를 호출하십시오.

관련 문제