protected void lvCategory_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "EditCategory") { try { btnSave.Visible = false; btnUpdate.Visible = true; btnDelete.Visible = true; btnCancel.Visible = true; Int64 categoryID = Convert.ToInt64(e.CommandArgument); hdCategoryID.Value = categoryID.ToString(); using (CategoryRT receiverTransfer = new CategoryRT()) { Category category = receiverTransfer.GetCategoryByID(categoryID); FillCategoryForEdit(category); } labelMessage.Text = string.Empty; } catch (Exception ex) { labelMessage.Text = "Error : " + ex.Message; labelMessage.ForeColor = System.Drawing.Color.Red; } } }
private void FillCategoryForEdit(Category category) { try { if (category != null) { txtName.Text = category.Name; txtSerialNo.Text = category.SerialNo.ToString(); using (CategoryRT receiverTransfer = new CategoryRT()) { if (category.ParentID != null) { var cat = receiverTransfer.GetCategoryByID(category.ParentID != null ? Convert.ToInt64(category.ParentID) : 0); txtParentCategoryID.Text = cat.Name; txtParentID.Text = category.ParentID != null?Convert.ToString(category.ParentID) : string.Empty; } else { txtParentCategoryID.Text = string.Empty; txtParentID.Text = string.Empty; } } Session[sessCategory] = category; } } catch (Exception ex) { labelMessage.Text = "Error : " + ex.Message; labelMessage.ForeColor = System.Drawing.Color.Red; } }