I have read tons of questions regarding the update of the grid ;not working, but I can't seem to find a solution :(
I a grid filled with a list of objects. When I press refresh it updates the lines, but when I add or delete an item the grid is not updated. When I change an object and save, the line IS updated.
My code:
And the command-functions:
the code is in a control that is created in a main page, if you want' I could add that code as well.
I've tried both the rebind and the NeedDataSource event, but that doesn't make any difference.
I really hope you guy's could help me out with this one.
Thanks
I a grid filled with a list of objects. When I press refresh it updates the lines, but when I add or delete an item the grid is not updated. When I change an object and save, the line IS updated.
My code:
protected override void Page_Init(object sender, EventArgs e) |
{ |
base.Page_Init(sender, e); |
CreateGrid(); |
} |
protected void Page_Load(object sender, System.EventArgs e) |
{ |
lblLocation.Text = Location.Title; |
if (!IsPublished) |
{ |
lblStatus.Text = " - " + _location.Status.ToString(); |
lblStatus.Visible = true; |
} |
if (_ajaxmanager != null) |
{ |
_ajaxmanager.AjaxSettings.AddAjaxSetting(Grid, Grid); |
} |
} |
public void CreateGrid() |
{ |
GridButtonColumn edit_col = new GridButtonColumn(); |
edit_col.Text = "wijzig"; |
edit_col.UniqueName = "EditColumn"; |
edit_col.CommandName = "Edit"; |
edit_col.ItemStyle.Width = Unit.Pixel(35); |
GridButtonColumn copy_col = new GridButtonColumn(); |
copy_col.Text = "kopieer"; |
copy_col.UniqueName = "CopyColumn"; |
copy_col.CommandName = "Copy"; |
copy_col.ItemStyle.Width = Unit.Pixel(40); |
GridButtonColumn del_col = new GridButtonColumn(); |
del_col.Text = "verwijder"; |
del_col.UniqueName = "DeleteColumn"; |
del_col.CommandName = "Delete"; |
del_col.ItemStyle.Width = Unit.Pixel(50); |
RadGrid grid = new RadGrid(); |
grid.UpdateCommand += new GridCommandEventHandler(grid_UpdateCommand); |
grid.DeleteCommand += new GridCommandEventHandler(grid_DeleteCommand); |
//grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound); |
grid.ID = "grdFreeplaces"; |
grid.AutoGenerateColumns = false; |
grid.ShowStatusBar = true; |
grid.Width = Unit.Pixel(737); |
grid.ClientSettings.AllowKeyboardNavigation = true; |
grid.ClientSettings.KeyboardNavigationSettings.InitInsertKey = GridFocusKeys.I; |
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template; |
grid.MasterTableView.EditFormSettings.FormTemplate = new VisualObjectEditorFreeDaysFormTemplate(this, _location); |
grid.MasterTableView.CommandItemSettings.AddNewRecordText = "Toevoegen"; |
grid.MasterTableView.CommandItemSettings.RefreshText = "Herladen"; |
if (IsPublished) |
grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom; |
else |
grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
grid.MasterTableView.EditMode = GridEditMode.PopUp; |
grid.MasterTableView.EditFormSettings.PopUpSettings.Width = Unit.Pixel(765); |
grid.MasterTableView.EditFormSettings.PopUpSettings.Height = Unit.Pixel(240); |
grid.DataSource = Location.FreePlaces; |
grid.MasterTableView.DataKeyNames = new string[] { "LexiconItemID" }; |
if (IsPublished) grid.MasterTableView.Columns.Add(edit_col); |
if (IsPublished) grid.MasterTableView.Columns.Add(del_col); |
grid.MasterTableView.Columns.Add(CreateDataColumn("Omschrijving", "Description")); |
grid.MasterTableView.Columns.Add(CreateDataColumn("Leeftijd", "AgeRangeDescription")); |
phFreePlace.Controls.Add(grid); |
} |
And the command-functions:
protected void grid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
bool isnew = false; |
GridEditableItem item = e.Item as GridEditableItem; |
VisualObjectEditor editor = (e.CommandSource as Button).Parent.FindControl("edtFormTemplate") as VisualObjectEditor; |
LexiconItem freeplace = null; |
Location.Location.Document.ContentControl.CheckOut(Framework, Framework.ActiveUser); |
if (item.ItemIndex < 0) |
{ |
freeplace = _location.Location.CreateNewFreePlace().LexiconItem; |
isnew = true; |
} |
else |
freeplace = Location.FindFreePlace(item.OwnerTableView.DataKeyValues[item.ItemIndex]["LexiconItemID"].ToString()).LexiconItem; |
editor.GetContentStorageValues(freeplace.Content.DocumentType, freeplace.Content); |
if (editor.Validate(freeplace)) |
{ |
Location.Location.GetFreePlaceContentField().LexiconItems.Add(freeplace); |
Location.Location.Document.ContentControl.Publish(Framework, Framework.ActiveUser); |
Grid.DataSource = Location.FreePlaces; |
Grid.Rebind(); |
} |
else |
{ |
Location.Location.Document.ContentControl.UndoCheckOut(Framework, Framework.ActiveUser); |
e.Canceled = true; |
} |
} |
protected void grid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
Location.Location.Document.ContentControl.CheckOut(Framework, Framework.ActiveUser); |
string lexiconitemid = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["LexiconItemID"].ToString(); |
Location.Location.DeleteFreePlace(lexiconitemid); |
Location.Location.Document.ContentControl.Publish(Framework, Framework.ActiveUser); |
Grid.DataSource = Location.FreePlaces; |
Grid.Rebind(); |
} |
the code is in a control that is created in a main page, if you want' I could add that code as well.
I've tried both the rebind and the NeedDataSource event, but that doesn't make any difference.
I really hope you guy's could help me out with this one.
Thanks