This is a migrated thread and some comments may be shown as answers.

Record not disappearing on Delete

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 23 Mar 2012, 09:28 PM
I have a RadGrid which takes as its datasource a programmatically generated DataTable, using LINQ to SQL. When I "Decline" a "Request", the record should be deleted, however, it doesn't disappear from the grid. To clarify, the record is deleted in the database, just not in the grid itself. Here's part of the code in the ItemCommand event:

if (e.CommandName == "Decline") {
    WellnessTeamRequest wtr = WellnessTeamRequest.FindByUserId(e.CommandArgument.ToString());
    wtr.Delete();
    requestsRadGrid.MasterTableView.ClearEditItems();
    requestsRadGrid.DataSource = GetRequestsDS();
    requestsRadGrid.DataBind();
     
 
}

Here's the helper method for the DataSource:

protected DataTable GetRequestsDS() {           
            DataTable dt = createEmptyDataSet(new string[] {"UserID", "Name", "Requested Team"});
            List<WellnessTeamRequest> requests = WellnessTeamRequest.GetAllRequests();
            foreach (WellnessTeamRequest request in requests) {
                DataRow newRow = dt.NewRow();
                newRow["UserID"] = request.UserId;
                newRow["Name"] = request.WellnessUser.User.FullName();
                newRow["Requested Team"] = request.WellnessTeam.TeamName;
                dt.Rows.Add(newRow);
            }
            return dt;
        }




I've tried it using both Rebind() and DataBind(). I can't just refresh the page, as the page actually has three grids on it, the one that is shown is decided using a dropdown and if I refresh the page the previously selected grid disappears. 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Mar 2012, 02:02 PM
Hi Kyle,

I have the similar issue when I bind the grid in PageLoad event(without setting !IsPostBack) . I assume that you are binding the grid in PageLoad event, which is Simple data binding technique. If you are using any advanced feature in grid(like insert,update,delete operation ), then a better approach is using "AdvancedData binding" using NeedDataSource event.

For more information about this can be available here.
Advanced Data-binding (using NeedDataSource event)

ASPX:
<telerik:RadGrid ID="requestsRadGrid"  runat="server" AutoGenerateColumns="False"
          OnItemCommand="requestsRadGrid_ItemCommand"
          onneeddatasource="requestsRadGrid_NeedDataSource">
         .  .  .  .  .  .  .
 </telerik:RadGrid>

C#:
protected void requestsRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
         requestsRadGrid.DataSource = GetRequestsDS();
       }
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
           if (e.CommandName == "Decline")
           {
               // your delete code
           }
       }

Thanks,
Shinu.
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or