hello community!
I am trying to perform Insert/edit operations in my grid through the usage of a WebUserControl Edit Form. In the context of my architecture, the form should be triggered through the itemcommand event.
I got 2 problems, i am not calling the form the right way, and i am getting an error in my bll method, that a i can't explain.
// UI Buttons with the commandname ahve the following structure <CommandItemTemplate> <telerik:RadButton CommandName="InitInsert" IsinEditmode="true" RenderMode="Lightweight" ID="AddNewRecordButton" runat="server" " NavigateUrl="~/Views/Projectos/Equipa/ViewEmissaoTimeSheetEdit.ascx" CommandArgument="ID"> </telerik:RadButton> </CommandItemTemplate> //BLL Insert/update and save methods, all 3 with similar structure ( "ListagemTimesheet" represents the DAL ) public void InsertFile(ListagemTimesheet model) { try { using (GestaoProjectosEntities lt = new GestaoProjectosEntities()) { var result = lt.ListagemTimesheets.SingleOrDefault(b => b.ID == model.ID); if (result != null) { result.ID = model.ID; result.IDRecursoHumano = model.IDRecursoHumano; result.IDEstadoTimesheet = model.IDEstadoTimesheet; result.FileContent = model.FileContent; result.Ficheiro = model.Ficheiro; result.DataEnvio = model.DataEnvio; result.FileTipo = model.FileTipo; result.AssinaturaTimesheet = model.AssinaturaTimesheet; result.Observações = model.Observações; lt.SaveChanges(); } } } //Grid_ItemCommand events if (e.CommandName == RadGrid.InitInsertCommandName) { UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); //Insert new values Hashtable newValues = new Hashtable(); newValues["IDRecursoHumano"] = (userControl.FindControl("rdpInvestigador") as RadTextBox).Text; newValues["IDEstadoTimesheet"] = (userControl.FindControl("rdbEstado") as RadComboBox).Text; newValues["AssinaturaTimesheet"] = (userControl.FindControl("txtAssinaturaTimesheet") as RadTextBox).Text; newValues["Observações"] = (userControl.FindControl("Obervaçoestxt") as RadTextBox).Text; newValues["DataEnvio"] = (userControl.FindControl("DataEnvio") as RadDatePicker).SelectedDate.ToString(); newValues["FileContent"] = (userControl.FindControl("RadAsyncUpload1") as RadAsyncUpload).TargetFolder.ToString(); try { this.listagembll.InsertFile(model); //model does not exist in current context error } catch (Exception ex) { //ShowErrorMessage(); } } if (e.CommandName == "Edit") { foreach (GridEditableItem item in gvTimesheets.EditItems) { GridEditFormItem formItem = e.Item as GridEditFormItem; string strID = item.GetDataKeyValue("ID").ToString(); GridDataItem dataItem = formItem.ParentItem as GridDataItem; } UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); Hashtable newValues = new Hashtable(); newValues["IDRecursoHumano"] = (userControl.FindControl("rdpInvestigador") as RadTextBox).Text; newValues["IDEstadoTimesheet"] = (userControl.FindControl("rdbEstado") as RadComboBox).Text; newValues["AssinaturaTimesheet"] = (userControl.FindControl("txtAssinaturaTimesheet") as RadTextBox).Text; newValues["Observações"] = (userControl.FindControl("Obervaçoestxt") as RadTextBox).Text; newValues["DataEnvio"] = (userControl.FindControl("DataEnvio") as RadDatePicker).SelectedDate.ToString(); newValues["FileContent"] = (userControl.FindControl("RadAsyncUpload1") as RadAsyncUpload).TargetFolder.ToString(); try { foreach (DictionaryEntry entry in newValues) { //listagembll.UpdateFile(model); } } catch (System.Exception) { //ShowErrorMessage(); } //GridEditFormItem editFormItem = (GridEditFormItem)e.Item; } }
Any ideas on what to do here?