Karl Johann Gudsteinsson
Top achievements
Rank 1
Karl Johann Gudsteinsson
asked on 04 Feb 2010, 03:11 PM
I am using RAdGrid two level hierarchy and userContols as Edit and Insert forms.
After creating entry in MasterTable I would like to open insert form for child record automaticly.
6 Answers, 1 is accepted
0
Hi Eydís,
Tsvetoslav
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Attached is a small sample that contains directions on how to achieve your scenario.
I hope it helps.
All the best,Tsvetoslav
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Shinu
Top achievements
Rank 2
answered on 05 Feb 2010, 08:12 AM
Hello Eydis Huld,
Here is the code library which shows how to access the last inserted record and selecting it.
Select Last Inserted Row
Use the same logic to find the record and use the following code snippet in order to expand the item and set the child item in insert mode.
CS:
Happy coding. :)
Shinu.
Here is the code library which shows how to access the last inserted record and selecting it.
Select Last Inserted Row
Use the same logic to find the record and use the following code snippet in order to expand the item and set the child item in insert mode.
CS:
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| . . . |
| foreach (GridDataItem item in RadGrid1.Items) |
| { |
| int intCategoryID = Convert.ToInt16(item["CategoryID"].Text); |
| if (intCategoryID == intLastCategoryID) |
| { |
| item.Expanded = true; |
| GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0]; |
| tableView.IsItemInserted = true; |
| } |
| } |
| . . . |
| } |
Happy coding. :)
Shinu.
0
Karl Johann Gudsteinsson
Top achievements
Rank 1
answered on 05 Feb 2010, 10:36 AM
With this code I can access the last entry in mastertable and open insert form for child entry.
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| if (!Page.IsPostBack) |
| { |
| int i = RadGrid1.MasterTableView.Items.Count; |
| if (i > 0) |
| { |
| GridDataItem editedItem = (GridDataItem)RadGrid1.MasterTableView.Items[i - 1]; |
| editedItem.ChildItem.NestedTableViews[0].IsItemInserted = true; |
| editedItem.Expanded = true; |
| } |
| } |
| } |
| TableInvoiceLines.EditFormSettings.EditFormType = GridEditFormType.WebUserControl; |
| TableInvoiceLines.EditFormSettings.UserControlName = ".uctrl/NewInvoiceLine.ascx"; |
| if (_newI == 1) |
| { |
| int i = RadGrid1.MasterTableView.Items.Count; |
| if (i > 0) |
| { |
| RadGrid1.MasterTableView.Items[i - 1].Expanded = true; |
| } |
| _newI = 0; |
| } |
0
Hi Eydís,
I assume that the reason for the first issue is connected with an incorrect path specified for the user control edit form. Please check it out and see if changing it makes any difference.
Regarding the other question: I am afraid that the provided information is not enough for determining the problem. Could you please provide the full page code?
Greetings,
Iana
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
I assume that the reason for the first issue is connected with an incorrect path specified for the user control edit form. Please check it out and see if changing it makes any difference.
Regarding the other question: I am afraid that the provided information is not enough for determining the problem. Could you please provide the full page code?
Greetings,
Iana
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Ívar Eiríksson
Top achievements
Rank 1
answered on 22 Feb 2010, 11:23 AM
here is code for the control would do yot need the hole solutions?
| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Web; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Telerik.Web.UI; |
| using iBillingManagers; |
| using iBillingData; |
| using System.Collections; |
| using System.Diagnostics; |
| using iBillingManagers.Exceptions; |
| using Telerik.Reporting.Processing; |
| using System.Configuration; |
| using iBillingReports; |
| using TelerikRadGridLocalization; |
| namespace iSolutions.uctrl |
| { |
| public partial class Invoice : BaseIBillingUserControl |
| { |
| #region private members |
| private static InvoiceManager _manager; |
| private GridTableView _tableInvoiceLines; |
| private int _newI; |
| #endregion |
| #region properties |
| public InvoiceManager Manager |
| { |
| get |
| { |
| if (null == _manager) _manager = new InvoiceManager(); |
| return _manager; |
| } |
| } |
| private GridTableView TableInvoiceLines |
| { |
| get |
| { |
| if (null == _tableInvoiceLines) |
| _tableInvoiceLines = new GridTableView(); |
| return _tableInvoiceLines; |
| } |
| } |
| #endregion |
| //Detail table stofnuð sérstaklega svo hægt sé að skipta um control henni tengd |
| #region private methods |
| private void CreateGrid() |
| { |
| Log.Debug("CreateGrid()"); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| //Smíða grid og skilgreina getu og útlit |
| RadGrid1 = new RadGrid(); |
| RadGrid1.ID = "RadGrid1"; |
| RadGrid1.AutoGenerateColumns = false; |
| RadGrid1.Skin = "Sitefinity"; |
| //RadGrid1.AutoGenerateDeleteColumn = true; |
| // RadGrid1.AutoGenerateEditColumn = true; |
| RadGrid1.AllowSorting = true; |
| RadGrid1.AllowPaging = true; |
| // RadGrid1.PageSize = 20; |
| RadGrid1.MasterTableView.PageSize = 25; |
| RadGrid1.ShowGroupPanel = true; |
| RadGrid1.ClientSettings.AllowDragToGroup = true; |
| RadGrid1.MasterTableView.CommandItemSettings.AddNewRecordText = "Nýr reikningur"; |
| RadGrid1.MasterTableView.CommandItemSettings.RefreshText = "Nýglæða"; |
| //RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true; |
| RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; |
| RadGrid1.MasterTableView.GroupsDefaultExpanded = true; |
| RadGrid1.ClientSettings.Selecting.AllowRowSelect = true; |
| // RadGrid1.ClientSettings.ClientEvents.OnRowSelected = "selected"; |
| RadGrid1.ItemCommand += new GridCommandEventHandler(Radgrid1_ItemCommand); |
| RadGrid1.ClientSettings.ClientEvents.OnRowDblClick = "RowDblClicked"; |
| // Búa til datatengingu, velja gögn og setja tengiId fyrir undirtöflu |
| // InvoiceManager manager = new InvoiceManager(); |
| // RadGrid1.DataSource = manager.GetInvoices(sessionUserId, 0); |
| RadGrid1.MasterTableView.DataKeyNames = new string[] { "InvoiceId" }; |
| // Velja og raða upp dálkum |
| RadGrid1.MasterTableView.AutoGenerateColumns = false; |
| GridEditCommandColumn commandColumn = new GridEditCommandColumn(); |
| RadGrid1.MasterTableView.Columns.Add(commandColumn); |
| commandColumn.ButtonType = GridButtonColumnType.ImageButton; |
| commandColumn.EditImageUrl = "../images/radgrid/Edit.gif"; |
| commandColumn.HeaderText = "Breyta"; |
| GridButtonColumn buttonColumn = new GridButtonColumn(); |
| RadGrid1.MasterTableView.Columns.Add(buttonColumn); |
| buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
| buttonColumn.ImageUrl = "../images/search.png"; |
| buttonColumn.HeaderText = "Skoða"; |
| buttonColumn.CommandName = "ViewInvoice"; |
| GridBoundColumn boundColumn; |
| boundColumn = new GridBoundColumn(); |
| RadGrid1.MasterTableView.Columns.Add(boundColumn); |
| boundColumn.HeaderText = "InvoiceID"; |
| boundColumn.DataField = "InvoiceID"; |
| boundColumn.Visible = false; |
| boundColumn = new GridBoundColumn(); |
| RadGrid1.MasterTableView.Columns.Add(boundColumn); |
| boundColumn.HeaderText = "CustomerId"; |
| boundColumn.DataField = "CustomerId"; |
| boundColumn.Visible = false; |
| string[,] ColumnNames = {{"Nafn","CustName"},{"Kennitala", "CustSSN"}, |
| {"Heimili", "CustAddress1"},{"Póstnúmer", "CustPnr"}, |
| {"Staður", "CustCity"}, |
| {"Lýsing", "Description"}, |
| {"Afsláttur","Discount"}, |
| // {"Samtals", ""},{"VSK samtals","VatWithDiscount"}, |
| {"Debit/Kredit","Type"}}; |
| for (int i = 0; i <= ColumnNames.GetUpperBound(0); i++) |
| { |
| boundColumn = new GridBoundColumn(); |
| boundColumn.HeaderText = ColumnNames[i, 0]; |
| boundColumn.DataField = ColumnNames[i, 1]; |
| boundColumn.ReadOnly = true; |
| RadGrid1.MasterTableView.Columns.Add(boundColumn); |
| } |
| GridNumericColumn numColumn = new GridNumericColumn(); |
| RadGrid1.MasterTableView.Columns.Add(numColumn); |
| numColumn.DataFormatString = "{0:###,###. kr}"; |
| numColumn.AllowRounding = true; |
| numColumn.DataField = "TotalVat"; |
| numColumn.HeaderText = "VSK samtals"; |
| numColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| numColumn = new GridNumericColumn(); |
| RadGrid1.MasterTableView.Columns.Add(numColumn); |
| numColumn.DataFormatString = "{0:###,###. kr}";//= "{0:n}"; |
| numColumn.AllowRounding = true; |
| numColumn.DataField = "TotalWithDiscount"; |
| numColumn.HeaderText = "Samtals"; |
| numColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| GridDateTimeColumn dateColumn = new GridDateTimeColumn(); |
| RadGrid1.MasterTableView.Columns.Add(dateColumn); |
| dateColumn.HeaderText = "Stofnað"; |
| dateColumn.DataField = "CreateDate"; |
| dateColumn.DataFormatString = "{0:dd/MM/yyyy}"; |
| //GridButtonColumn buttonColumn = new GridButtonColumn(); |
| //RadGrid1.MasterTableView.Columns.Add(buttonColumn); |
| //buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
| //buttonColumn.ImageUrl = "../images/search.png"; |
| //buttonColumn.HeaderText = "Skoða"; |
| //buttonColumn.CommandName = "ViewInvoice"; |
| buttonColumn = new GridButtonColumn(); |
| RadGrid1.MasterTableView.Columns.Add(buttonColumn); |
| buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
| buttonColumn.ImageUrl = "../images/radgrid/las.gif"; |
| buttonColumn.CommandName = "IssueInvoice"; |
| buttonColumn.HeaderText = "Gefa út"; |
| buttonColumn = new GridButtonColumn(); |
| RadGrid1.MasterTableView.Columns.Add(buttonColumn); |
| buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
| buttonColumn.ImageUrl = "../images/radgrid/Delete.gif"; |
| buttonColumn.CommandName = "delete"; |
| buttonColumn.HeaderText = "Eyða"; |
| RadGrid1.MasterTableView.EditFormSettings.EditColumn.UniqueName = "EditCommandColumn1"; |
| RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl; |
| RadGrid1.MasterTableView.EditFormSettings.UserControlName = "uctrl/EditInvoice.ascx"; |
| RadGrid1.PreRender += new EventHandler(RadGrid1_PreRender); |
| RadGrid1.ColumnCreated += new GridColumnCreatedEventHandler(RadGrid1_ColumnCreated); |
| //--------------------------------------------- |
| //Detail table |
| TableInvoiceLines.PageSize = 200; |
| TableInvoiceLines.DataKeyNames = new string[] { "InvoiceId" }; |
| // skilgreina getu |
| TableInvoiceLines.CommandItemDisplay = GridCommandItemDisplay.Bottom; |
| TableInvoiceLines.GroupsDefaultExpanded = true; |
| TableInvoiceLines.HierarchyLoadMode = GridChildLoadMode.Client; |
| // tengja töflur saman |
| GridRelationFields relationFields = new GridRelationFields(); |
| relationFields.MasterKeyField = "InvoiceId"; |
| relationFields.DetailKeyField = "InvoiceId"; |
| TableInvoiceLines.ParentTableRelation.Add(relationFields); |
| // skella undirtöflu inn í yfirtöflu |
| RadGrid1.MasterTableView.DetailTables.Add(TableInvoiceLines); |
| //velja dálka og raða |
| TableInvoiceLines.AutoGenerateColumns = false; |
| TableInvoiceLines.Columns.Add(commandColumn); |
| TableInvoiceLines.EditFormSettings.EditColumn.UniqueName = "EditcommanColumn2"; |
| TableInvoiceLines.EditFormSettings.EditFormType = GridEditFormType.WebUserControl; |
| TableInvoiceLines.EditFormSettings.UserControlName = ".uctrl/NewInvoiceLine.ascx"; |
| TableInvoiceLines.CommandItemSettings.AddNewRecordText = "Ný vörulína"; |
| TableInvoiceLines.CommandItemSettings.RefreshText = "Nýglæða"; |
| boundColumn = new GridBoundColumn(); |
| TableInvoiceLines.Columns.Add(boundColumn); |
| boundColumn.HeaderText = "InvoiceID"; |
| boundColumn.DataField = "InvoiceID"; |
| boundColumn.Visible = false; |
| boundColumn = new GridBoundColumn(); |
| TableInvoiceLines.Columns.Add(boundColumn); |
| boundColumn.HeaderText = "Línunúmer"; |
| boundColumn.DataField = "LineNumber"; |
| boundColumn.Visible = false; |
| string[,] ColumnNamesDetail = {{"Vörunúmer", "PNumber"},{"Vörulýsing", "Description"}, |
| {"Magn", "Quantity"}, {"Eining", "Unit"}, |
| {"Afsláttur","Discount"}, |
| {"VSK prósenta", "VatPct"}, |
| // {"Verð", "Price"} |
| }; |
| boundColumn = new GridBoundColumn(); |
| for (int i = 0; i <= ColumnNamesDetail.GetUpperBound(0); i++) |
| { |
| boundColumn = new GridBoundColumn(); |
| TableInvoiceLines.Columns.Add(boundColumn); |
| boundColumn.HeaderText = ColumnNamesDetail[i, 0]; |
| boundColumn.DataField = ColumnNamesDetail[i, 1]; |
| } |
| numColumn = new GridNumericColumn(); |
| TableInvoiceLines.Columns.Add(numColumn); |
| numColumn.DataFormatString = "{0:###,###.## kr}";//= "{0:n}"; |
| numColumn.AllowRounding = true; |
| numColumn.DataField = "Price"; |
| numColumn.HeaderText = "Verð"; |
| numColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| numColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right; |
| //GridCalculatedColumn calcColumn = new GridCalculatedColumn(); |
| //TableInvoiceLines.Columns.Add(calcColumn); |
| //calcColumn.HeaderText = "Samtals"; |
| //string[] fields = { "Price", "Quantity", "VatPct", "Discount" }; |
| //calcColumn.DataFields = fields; |
| //calcColumn.Expression = " (({1} * {0} * {2}/ 100) + {1} * {0}) - (({1} * {0} * {2}/ 100 + {1} * {0})* {3} / 100) "; |
| //calcColumn.DataFormatString = "{0:###,###. kr}"; |
| //calcColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| //calcColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right; |
| numColumn = new GridNumericColumn(); |
| TableInvoiceLines.Columns.Add(numColumn); |
| numColumn.DataFormatString = "{0:###,###. kr}";//= "{0:n}"; |
| numColumn.AllowRounding = true; |
| numColumn.DataField = "SamtalsAnVsk"; |
| numColumn.HeaderText = "Samtals"; |
| numColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right; |
| numColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| buttonColumn = new GridButtonColumn(); |
| TableInvoiceLines.Columns.Add(buttonColumn); |
| buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
| buttonColumn.ImageUrl = "../images/radgrid/Delete.gif"; |
| buttonColumn.CommandName = "delete"; |
| buttonColumn.HeaderText = "Eyða"; |
| this.PlaceHolder1.Controls.Clear(); |
| this.PlaceHolder1.Controls.Add(RadGrid1); |
| RadGrid1.InsertCommand += new GridCommandEventHandler(RadGrid1_InsertCommand); |
| RadGrid1.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand); |
| RadGrid1.EditCommand += new GridCommandEventHandler(RadGrid1_EditCommand); |
| RadGrid1.DeleteCommand += new GridCommandEventHandler(RadGrid1_DeleteCommand); |
| RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource); |
| } |
| private InvoiceBasic NewReport(decimal UserId, decimal InvoiceId) |
| { |
| Log.Debug("NewReport(decimal UserId, decimal InvoiceId)"); |
| Log.DebugFormat("UserId:{0}, InvoiceId:{1})", UserId, InvoiceId); |
| InvoiceBasic invoiceBasic = new InvoiceBasic(UserId, InvoiceId); |
| InvoiceLines invoiceLines = new InvoiceLines(UserId, InvoiceId); |
| invoiceBasic.subReport1.ReportSource.DataSource = invoiceLines.DataSource; |
| return invoiceBasic; |
| } |
| private byte[] ExportToPDF(Telerik.Reporting.Report reportToExport) |
| { |
| Log.Debug("ExportToPDF(Telerik.Reporting.Report reportToExport)"); |
| ReportProcessor reportProcessor = new ReportProcessor(); |
| RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, null); |
| return result.DocumentBytes; |
| } |
| #endregion |
| protected void Page_Load(object source, System.EventArgs e) |
| { |
| // RadGrid1.Localize(); |
| } |
| protected void Page_Init(object source, System.EventArgs e) |
| { |
| Log.Debug("Page_Init(object source, System.EventArgs e)"); |
| _newI = 0; |
| CreateGrid(); |
| RadGrid1.Localize(); |
| } |
| #region RadGrid handlers |
| protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) |
| { |
| if (e.Column.UniqueName == "ExpandColumn") |
| { |
| GridExpandColumn boundColumn = e.Column as GridExpandColumn; |
| boundColumn.HeaderText = "Vöru línur"; |
| } |
| } |
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| if (!Page.IsPostBack) |
| { |
| int i = RadGrid1.MasterTableView.Items.Count; |
| if (i > 0) |
| { |
| GridDataItem editedItem = (GridDataItem)RadGrid1.MasterTableView.Items[i - 1]; |
| // editedItem.ChildItem.NestedTableViews[0].IsItemInserted = true; |
| editedItem.Expanded = true; |
| } |
| } |
| //if (_newI == 1) |
| //{ |
| // int i = RadGrid1.MasterTableView.Items.Count; |
| // if (i > 0) |
| // { |
| // RadGrid1.MasterTableView.Items[i - 1].Expanded = true; |
| // GridDataItem editedItem = (GridDataItem)RadGrid1.MasterTableView.Items[i - 1]; |
| // editedItem.ChildItem.NestedTableViews[0].IsItemInserted = true; |
| // editedItem.Expanded = true; |
| // editedItem.ChildItem.NestedTableViews[0].Rebind(); |
| // } |
| // _newI = 0; |
| //} |
| } |
| protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| Log.Debug("RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)"); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| try |
| { |
| RadGrid1.DataSource = Manager.GetInvoices(sessionUserId, 0); |
| RadGrid1.MasterTableView.DetailTables[0].DataSource = Manager.GetInvoiceLines(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| Log.Debug("RadGrid1_InsertCommand(object source, GridCommandEventArgs e)"); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| GridEditFormItem editItem = (GridEditFormItem)e.Item; |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| Hashtable newnewValues = new Hashtable(); |
| string test = (userControl.FindControl("txtCustName") as System.Web.UI.WebControls.TextBox).Text; |
| if (test.Length > 1) |
| { |
| newValues["check"] = (userControl.FindControl("cboxVidskiptavinur") as System.Web.UI.WebControls.CheckBox).Checked; |
| newValues["Description"] = (userControl.FindControl("txtDescription") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustName"] = (userControl.FindControl("txtCustName") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustSSN"] = (userControl.FindControl("txtCustSSN") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustAddress1"] = (userControl.FindControl("txtCustAddress1") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustPnr"] = (userControl.FindControl("txtCustPnr") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustCity"] = (userControl.FindControl("txtCustCity") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["DefaultDiscount"] = (userControl.FindControl("txtDefaultDiscount") as System.Web.UI.WebControls.TextBox).Text; |
| newValues["CustCountryCode"] = (userControl.FindControl("DDCountrycode") as System.Web.UI.WebControls.DropDownList).Text; |
| InvoiceFix invoiceFix = new InvoiceFix(); |
| invoiceFix.Description = newValues["Description"] as string; |
| invoiceFix.CustName = newValues["CustName"] as string; |
| invoiceFix.CustSSN = newValues["CustSSN"] as string; |
| invoiceFix.CustAddress1 = newValues["CustAddress1"] as string; |
| invoiceFix.CustAddress2 = newValues["CustAddress2"] as string; |
| invoiceFix.CustPnr = newValues["CustPnr"] as string; |
| invoiceFix.CustCity = newValues["CustCity"] as string; |
| invoiceFix.CustCountry = newValues["CustCountryCode"] as string; |
| try |
| { |
| invoiceFix.Discount = Convert.ToDecimal(newValues["DefaultDiscount"] as string); |
| } |
| catch |
| { |
| invoiceFix.Discount = 0; |
| } |
| invoiceFix.Type = "D"; |
| try |
| { |
| Manager.SaveInvoice(sessionUserId, invoiceFix); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| else |
| { |
| iBillingData.Invoice invoice = new iBillingData.Invoice(); |
| invoice.Description = (userControl.FindControl("txtDescription") as System.Web.UI.WebControls.TextBox).Text; |
| invoice.CustomerId = Convert.ToDecimal((userControl.FindControl("DD") as DropDownList).Text); |
| invoice.Type = "D"; |
| try |
| { |
| Manager.SaveInvoice(1, invoice); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| try |
| { |
| ((RadGrid)source).DataSource = Manager.GetInvoices(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| _newI = 1; |
| try |
| { |
| if (Convert.ToBoolean(newValues["check"]) == true) |
| { |
| Customer customer = new Customer(); |
| customer.Name = newValues["CustName"] as string; |
| customer.UserId = sessionUserId; |
| try |
| { |
| decimal defaultDiscount = Convert.ToDecimal(newValues["DefaultDiscount"] as string); |
| customer.DefaultDiscount = defaultDiscount; |
| } |
| catch |
| { |
| customer.DefaultDiscount = 0; |
| } |
| // customer.Comment = newValues["Comment"] as string; |
| iBillingData.CustomerInfo custInfo = new iBillingData.CustomerInfo(); |
| custInfo.Name = newValues["CustName"] as string; |
| custInfo.SSN = newValues["CustSSN"] as string; |
| custInfo.Address1 = newValues["CustAddress1"] as string; |
| custInfo.Address2 = newValues["CustAddress2"] as string; |
| custInfo.Pnr = newValues["CustPnr"] as string; |
| custInfo.City = newValues["CustCity"] as string; |
| custInfo.Country = new Country(); |
| custInfo.Country.CountryCode = "IS"; |
| custInfo.ContactType = 1; |
| CustomerManager manager = new CustomerManager(); |
| try |
| { |
| manager.SaveCustomer(sessionUserId, customer, custInfo); |
| } |
| catch (iBillingCustomerManagerException ce) |
| { |
| Log.Error("Data connection excception", ce); |
| } |
| } |
| } |
| catch { } |
| // RadGrid1.Rebind(); |
| } |
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| Log.Debug("RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)"); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); GridEditFormItem editItem = (GridEditFormItem)e.Item; |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| InvoiceFix invoiceFix = new InvoiceFix(); |
| try |
| { |
| invoiceFix.Description = (userControl.FindControl("txtDescription") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.InvoiceId = Convert.ToDecimal((userControl.FindControl("txtInvoiceId") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceFix.CustomerId = Convert.ToDecimal((userControl.FindControl("txtCustomerId") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceFix.CustName = (userControl.FindControl("txtCustName") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.CustSSN = (userControl.FindControl("txtCustSSN") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.CustAddress1 = (userControl.FindControl("txtCustAddress1") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.CustPnr = (userControl.FindControl("txtCustPnr") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.CustCity = (userControl.FindControl("txtCustCity") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceFix.State = EntityState.Changed; |
| invoiceFix.Discount = Convert.ToDecimal((userControl.FindControl("txtDefaultDiscount") as System.Web.UI.WebControls.TextBox).Text); |
| try |
| { |
| Manager.SaveInvoice(sessionUserId, invoiceFix); |
| ((RadGrid)source).DataSource = Manager.GetInvoices(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| catch |
| { |
| InvoiceLineFix invoiceLineFix = new InvoiceLineFix(); |
| invoiceLineFix.InvoiceId = Convert.ToDecimal((userControl.FindControl("txtInvoiceId") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceLineFix.PNumber = (userControl.FindControl("txtPNumber") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Description = (userControl.FindControl("txtPDescription") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Quantity = Convert.ToDecimal((userControl.FindControl("txtQuantity") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceLineFix.Unit = (userControl.FindControl("txtUnit") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Price = Convert.ToDecimal((userControl.FindControl("txtPrice") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceLineFix.VatPct = Convert.ToDecimal((userControl.FindControl("DDVatPct") as System.Web.UI.WebControls.DropDownList).Text); |
| invoiceLineFix.Discount = Convert.ToDecimal((userControl.FindControl("txtDiscount") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceLineFix.LineNumber = Convert.ToInt16((userControl.FindControl("txtLineNumber") as System.Web.UI.WebControls.TextBox).Text); |
| invoiceLineFix.State = EntityState.Changed; |
| try |
| { |
| Manager.SaveInvoiceLine(1, invoiceLineFix); |
| ((RadGrid)source).DataSource = Manager.GetInvoiceLines(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| } |
| protected void Radgrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| Log.Debug("Radgrid1_ItemCommand(object source, GridCommandEventArgs e)"); |
| Log.DebugFormat("Grid command:{0}", e.CommandName); |
| string command = e.CommandName; |
| #region IssueInvoice |
| if (e.CommandName == "IssueInvoice") |
| { |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| GridEditableItem editItem = (GridEditableItem)e.Item; |
| Hashtable newnewValues = new Hashtable(); |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem); |
| decimal InvoiceId = Convert.ToDecimal(newValues["InvoiceID"] as string); |
| try |
| { |
| Manager.IssueInvoice(sessionUserId, InvoiceId); |
| RadGrid1.DataSource = Manager.GetInvoices(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| #endregion |
| #region ViewInvoice |
| if (e.CommandName == "ViewInvoice") |
| { |
| GridEditableItem editItem = (GridEditableItem)e.Item; |
| // extract InvoiceId from the grid and UserId from session |
| Hashtable newnewValues = new Hashtable(); |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| decimal sessionInvoiceId = Convert.ToDecimal(newValues["InvoiceID"]); |
| string createDate = Convert.ToString(newValues["CreateDate"]); |
| Session["InvoiceId"] = sessionInvoiceId; |
| // display report in a new window |
| Response.ContentType = "application/octet-stream"; |
| Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Proposal-{0}.pdf", createDate)); |
| byte[] array = ExportToPDF(NewReport(sessionUserId, sessionInvoiceId)); |
| Response.OutputStream.Write(array, 0, array.Length); |
| } |
| #endregion |
| #region InitInsert |
| if (e.CommandName == "InitInsert") |
| { |
| RadGrid1.MasterTableView.EditFormSettings.UserControlName = "uctrl/NewInvoice.ascx"; |
| TableInvoiceLines.EditFormSettings.UserControlName = "uctrl/NewInvoiceLine.ascx"; |
| } |
| #endregion |
| #region InsertInvoiceLineLong |
| if (e.CommandName == "InsertInvoiceLineLong") |
| { |
| GridEditFormItem editItem = (GridEditFormItem)e.Item; |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem); |
| decimal parId = Convert.ToDecimal(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["InvoiceId"]); |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| InvoiceLineFix invoiceLineFix = new InvoiceLineFix(); |
| invoiceLineFix.InvoiceId = parId; // Convert.ToDecimal((userControl.FindControl("txtInvoiceId") as TextBox).Text); |
| invoiceLineFix.PNumber = (userControl.FindControl("txtPNumber") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Description = (userControl.FindControl("txtPDescription") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Unit = (userControl.FindControl("txtUnit") as System.Web.UI.WebControls.TextBox).Text; |
| invoiceLineFix.Price = Convert.ToDecimal((userControl.FindControl("txtPrice") as System.Web.UI.WebControls.TextBox).Text); |
| try |
| { |
| decimal Quantity = Convert.ToDecimal((userControl.FindControl("txtQuantity") as System.Web.UI.WebControls.TextBox).Text); |
| if (Quantity == 0) |
| { |
| invoiceLineFix.Quantity = 1; |
| } |
| else |
| { |
| invoiceLineFix.Quantity = Quantity; |
| } |
| } |
| catch |
| { |
| invoiceLineFix.Quantity = 1; |
| } |
| string test = (userControl.FindControl("VatList") as System.Web.UI.WebControls.DropDownList).Text; |
| invoiceLineFix.VatPct = Convert.ToDecimal((userControl.FindControl("VatList") as System.Web.UI.WebControls.DropDownList).Text); |
| string discount = (userControl.FindControl("txtDiscount") as System.Web.UI.WebControls.TextBox).Text; |
| try |
| { |
| invoiceLineFix.Discount = Convert.ToDecimal((userControl.FindControl("txtDiscount") as System.Web.UI.WebControls.TextBox).Text); |
| } |
| catch |
| { |
| invoiceLineFix.Discount = 0; |
| } |
| try |
| { |
| Manager.SaveInvoiceLine(sessionUserId, invoiceLineFix); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| try |
| { |
| bool AddProd = (userControl.FindControl("cboxProduct") as System.Web.UI.WebControls.CheckBox).Checked; |
| if (AddProd == true) |
| { |
| Hashtable newnewValues = new Hashtable(); |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem); |
| Product product = new Product(); |
| product.PNumber = (userControl.FindControl("txtPNumber") as System.Web.UI.WebControls.TextBox).Text; |
| product.Description = (userControl.FindControl("txtPDescription") as System.Web.UI.WebControls.TextBox).Text; |
| product.Unit = (userControl.FindControl("txtUnit") as System.Web.UI.WebControls.TextBox).Text; |
| product.Price = Convert.ToDecimal((userControl.FindControl("txtPrice") as System.Web.UI.WebControls.TextBox).Text); |
| product.VatPct = Convert.ToDecimal((userControl.FindControl("VatList") as System.Web.UI.WebControls.DropDownList).Text); |
| try |
| { |
| iBillingManagers.ProductManager prodMan = new ProductManager(); |
| prodMan.SaveProduct(sessionUserId, product); |
| } |
| catch (iBillingProductManagerException pe) |
| { |
| Log.Error("Data connection excception", pe); |
| } |
| } |
| } |
| catch { } |
| } |
| #endregion |
| #region InsertInvoiceLineSimple |
| if (e.CommandName == "InsertInvoiceLineSimple") |
| { |
| GridEditFormItem editItem = (GridEditFormItem)e.Item; |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem); |
| decimal parId = (decimal)(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["InvoiceId"]); |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| InvoiceLine invoiceLine = new InvoiceLine(); |
| invoiceLine.InvoiceId = parId; |
| invoiceLine.Product = new Product(); |
| invoiceLine.Product.Id = Convert.ToDecimal((userControl.FindControl("productList") as DropDownList).Text); |
| try |
| { |
| decimal Quantity = Convert.ToDecimal((userControl.FindControl("txtQuantity") as System.Web.UI.WebControls.TextBox).Text); |
| if (Quantity == 0) |
| { |
| invoiceLine.Quantity = 1; |
| } |
| else |
| { |
| invoiceLine.Quantity = Quantity; |
| } |
| } |
| catch |
| { |
| invoiceLine.Quantity = 1; |
| } |
| try |
| { |
| Manager.SaveInvoiceLine(sessionUserId, invoiceLine); |
| RadGrid1.Rebind(); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| #endregion |
| } |
| protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e) |
| { |
| Log.Debug("RadGrid1_EditCommand(object source, GridCommandEventArgs e)"); |
| RadGrid1.MasterTableView.EditFormSettings.UserControlName = "uctrl/EditInvoice.ascx"; |
| TableInvoiceLines.EditFormSettings.UserControlName = "uctrl/EditInvoiceLine.ascx"; |
| } |
| protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e) |
| { |
| Log.Debug("RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)"); |
| decimal sessionUserId = Convert.ToDecimal(Session["UserId"]); |
| GridEditableItem editItem = (GridEditableItem)e.Item; |
| Hashtable newnewValues = new Hashtable(); |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem); |
| string lineNumber = newValues["LineNumber"] as string; |
| if (lineNumber == null) |
| { |
| iBillingData.InvoiceFix invoiceFix = new InvoiceFix(); |
| invoiceFix.InvoiceId = Convert.ToDecimal(newValues["InvoiceID"] as string); |
| invoiceFix.State = EntityState.Deleted; |
| try |
| { |
| Manager.SaveInvoice(1, invoiceFix); |
| ((RadGrid)source).DataSource = Manager.GetInvoices(sessionUserId, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| else |
| { |
| iBillingData.InvoiceLineFix invoiceLineFix = new InvoiceLineFix(); |
| invoiceLineFix.InvoiceId = Convert.ToDecimal(newValues["InvoiceID"] as string); |
| invoiceLineFix.LineNumber = Convert.ToInt16(newValues["LineNumber"] as string); |
| invoiceLineFix.State = EntityState.Deleted; |
| try |
| { |
| Manager.SaveInvoiceLine(1, invoiceLineFix); |
| ((RadGrid)source).DataSource = Manager.GetInvoiceLines(1, 0); |
| } |
| catch (iBillingInvoiceManagerException ie) |
| { |
| Log.Error("Data connenction exception", ie); |
| } |
| } |
| } |
| #endregion |
| } |
| } |
0
Hi Ívar,
I checked the code and here are my findings:
- When creating the grid dynamically on Page_Init, you first need to set the column' properties and then add the column to the grid table view columns collection, as described here.
- You can also try modifying the EditFormSetting.UserControlName properties as below and see if the errors persist:
Additionally, you can open a formal support ticket and send us a runnable version of the problematic page/user control so we could debug it and try finding a proper resolution for you.
Regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I checked the code and here are my findings:
- When creating the grid dynamically on Page_Init, you first need to set the column' properties and then add the column to the grid table view columns collection, as described here.
- You can also try modifying the EditFormSetting.UserControlName properties as below and see if the errors persist:
RadGrid1.MasterTableView.EditFormSettings.UserControlName = "~/uctrl/EditInvoice.ascx"; TableInvoiceLines.EditFormSettings.UserControlName = "~/uctrl/NewInvoiceLine.ascx";Additionally, you can open a formal support ticket and send us a runnable version of the problematic page/user control so we could debug it and try finding a proper resolution for you.
Regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.