CheckBoxList SubCategoryChkboxLst; protected void CategoryChkboxLst_SelectedIndexChanged(object sender, EventArgs e) { for (int i = 0; i < CategoryChkboxLst.Items.Count; i++) { if (CategoryChkboxLst.Items[i].Selected == true) { objdc.ItemID = Convert.ToInt32(CategoryChkboxLst.Items[i].Value); DataTable dt = new DataTable(); dt = objbl.GetSubCategories(ref objdc); SubCategoryChkboxLst = new CheckBoxList(); SubCategoryChkboxLst.DataSource = dt; SubCategoryChkboxLst.ID = "SubCategoryChkboxLst_" + objdc.ItemID; SubCategoryChkboxLst.DataTextField = "SUB_ITEM_NAME"; SubCategoryChkboxLst.DataValueField = "SUB_ITEM_ID"; SubCategoryChkboxLst.DataBind(); SubCategoryChkboxLst.RepeatColumns = 5; SubCategoryChkboxLst.RepeatDirection = RepeatDirection.Horizontal; //lblYear.ID = "lbl_" + li.Value; //adding to panel for appearing in specified location SubCategoryPnl.Controls.Add(SubCategoryChkboxLst); SubCategoryPnl.Controls.Add(new LiteralControl("<br>")); } } }
null
protected void SaveImgbtn_Click(object sender, ImageClickEventArgs e) { try { if (ProductNameCmbBox.SelectedIndex > 0) { //karthik written code for (int i = 0; i < CategoryChkboxLst.Items.Count; i++) { if (CategoryChkboxLst.Items[i].Selected == true) { objdc.ItemID = Convert.ToInt32(CategoryChkboxLst.Items[i].Value); string stId="SubCategoryChkboxLst_"+objdc.ItemID; CheckBoxList cklt = (CheckBoxList)Page.FindControl(stId); //here I am getting null ie cklt is null foreach (ListItem item in cklt.Items) { if (item.Selected) { objdc.subcategory += item.Value; //string Activities += item.Value; } } } } // code end objdc.insertedby = Session["UserId"].ToString(); int result = objbl.InsertProductscheme(ref objdc); if (result == 1) { GridBindMethod(); Literal li = new Literal(); li.Text = "<script>alert('Data Inserted Sucessfully');</script>"; Page.Controls.Add(li); Clearfields(); } else { Literal li = new Literal(); li.Text = "<script>alert('Insertion Failed');</script>"; Page.Controls.Add(li); } } } catch (Exception ex) { log.Error(ex.Message, ex); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)