protected void Page_Load(object sender, EventArgs e) { txtMediaTitle.Visible = false; lstMediaType.Visible = false; chkActive.Visible = false; lblMediaTitle.Visible = false; lblMediaType.Visible = false; lblActive.Visible = false; txtProductID.Visible = false; lblProductID.Visible = false; btnSave.Visible = false; btnCancel.Visible = false; if (!IsPostBack) { lstMediaType.Items.Add("Audio"); lstMediaType.Items.Add("Video"); BindData(); var action = Request.QueryString["action"]; if (action != null) { if (action == "e") { //edit var id = Request.QueryString["id"]; if (!string.IsNullOrEmpty(id)) { if(Helper.IsNumeric(id)) { ViewState["MediaID"] = id; MediaBAL bal = new MediaBAL(); MediaGroup mediagroup = bal.GetMediaGroup(Int32.Parse(id)); txtMediaTitle.Text = mediagroup.MediaTitle; txtProductID.Text = mediagroup.ProductID.ToString(); lstMediaType.SelectedValue = mediagroup.MediaType; chkActive.Checked = mediagroup.Active; txtMediaTitle.Visible = true; lstMediaType.Visible = true; chkActive.Visible = true; lblMediaTitle.Visible = true; lblMediaType.Visible = true; lblActive.Visible = true; btnSave.Visible = true; btnCancel.Visible = true; txtProductID.Visible = true; lblProductID.Visible = true; } } } if (action == "d") { //delete var id = Request.QueryString["id"]; if (!string.IsNullOrEmpty(id)) { if (Helper.IsNumeric(id)) { ViewState["MediaID"] = id; MediaBAL bal = new MediaBAL(); bal.DeleteMediaGroup(Int32.Parse(id)); BindData(); Response.Redirect("/editvideomain.aspx"); } } } } } }
private void BindData() { MediaBAL bal = new MediaBAL(); List<MediaGroup> items = bal.GetMediaGroups(); lstMediaGroups.DataSource = items; lstMediaGroups.DataBind(); if (items.Count() == 0) { lblPage.Visible = false; lvDataPager1.Visible = false; } else { lblPage.Visible = true; lvDataPager1.Visible = true; } }