void lvMain_ItemUpdating(object sender, ListViewUpdateEventArgs e) { // get Id being updated int id = Int32.Parse(lvMain.DataKeys[lvMain.EditIndex].Value.ToString()); // get the current item being edited ListViewItem item = lvMain.Items[lvMain.EditIndex]; if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingPackage.Count > 0) { ShippingMethodDto.ShippingPackageRow row = _ShippingMethodDto.ShippingPackage.FindByShippingPackageId(id); DropDownList ddl = (DropDownList)item.FindControl("PackagesList"); if (ddl != null && ddl.Items.Count > 0) { row.PackageId = Int32.Parse(ddl.SelectedValue); } TextBox tbName = item.FindControl("tbPackageName") as TextBox; if (tbName != null) { row.PackageName = tbName.Text; } } // exit the edit mode lvMain.EditIndex = -1; // bind the listview BindForm(); }
void AddPackageItem(ListViewItem item) { DropDownList ddl = (DropDownList)item.FindControl("PackagesList"); if (ddl != null && ddl.Items.Count > 0) { if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingOption.Count > 0) { ShippingMethodDto.ShippingPackageRow row = _ShippingMethodDto.ShippingPackage.NewShippingPackageRow(); row.ShippingOptionId = _ShippingMethodDto.ShippingOption[0].ShippingOptionId; row.PackageId = Int32.Parse(ddl.SelectedValue); TextBox tbName = item.FindControl("tbPackageName") as TextBox; if (tbName != null) { row.PackageName = tbName.Text; } if (row.RowState == DataRowState.Detached) { _ShippingMethodDto.ShippingPackage.Rows.Add(row); } } } // hide the text boxes CancelInsertMode(); // bind the ListView BindForm(); }
void lvMain_ItemDeleting(object sender, ListViewDeleteEventArgs e) { // get the current item being deleted int id = Int32.Parse(lvMain.DataKeys[e.ItemIndex].Value.ToString()); // delete shippingpackage with ShippingPackageId==id ShippingMethodDto.ShippingPackageRow shPackageRow = _ShippingMethodDto.ShippingPackage.FindByShippingPackageId(id); if (shPackageRow != null) { shPackageRow.Delete(); } BindForm(); }
void lvMain_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem && lvMain.EditIndex != -1) { int id = Int32.Parse(lvMain.DataKeys[lvMain.EditIndex].Value.ToString()); ShippingMethodDto.ShippingPackageRow shPackageRow = _ShippingMethodDto.ShippingPackage.FindByShippingPackageId(id); if (shPackageRow != null) { // select package in packages DropDownList DropDownList ddl = (DropDownList)e.Item.FindControl("PackagesList"); if (ddl != null) { ManagementHelper.SelectListItem(ddl, shPackageRow.PackageId.ToString()); } } } }
void lvMain_ItemEditing(object sender, ListViewEditEventArgs e) { // set the ListView to Edit mode lvMain.EditIndex = e.NewEditIndex; int id = Int32.Parse(lvMain.DataKeys[lvMain.EditIndex].Value.ToString()); ShippingMethodDto.ShippingPackageRow shPackageRow = _ShippingMethodDto.ShippingPackage.FindByShippingPackageId(id); if (shPackageRow != null) { // select package in package dropdown DropDownList ddl = (DropDownList)lvMain.Items[e.NewEditIndex].FindControl("PackageList"); if (ddl != null) { ManagementHelper.SelectListItem(ddl, shPackageRow.PackageId); } } // bind the ListView BindForm(); }