2
Answers

How can i keep selected checkbox items values ?

Ekrem Tapan

Ekrem Tapan

8y
331
1
I have a one dropdownlist and checkbox items. How can i make when i keep selected items when change dropdown listitem.
 
 
  1. protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3.     ddlList.AppendDataBoundItems = true;  
  4.     StringBuilder builder = new StringBuilder();  
  5.     string sqlQueryOcc = "";  
  6.     sqlQueryOcc += " select child.CODE,child.TITLE,child.PARENT_CODE,child.YEARS, parent.INDUS_CAT_NAME";  
  7.     sqlQueryOcc += " from SALARY_INDS_OCCNAME as parent ";  
  8.     sqlQueryOcc += " inner join dbo.SALARY_INDS_OCCSUBNAME as child ";  
  9.     sqlQueryOcc += " on parent.INDUS_CAT_CODE = child.PARENT_CODE";  
  10.     sqlQueryOcc += " where child.PARENT_CODE = '" + ddlList.SelectedValue + "' and child.YEARS = '" + ddlYear.SelectedValue + "'";  
  11.     sqlQueryOcc += " group by child.CODE,child.TITLE , child.PARENT_CODE ,child.YEARS, parent.INDUS_CAT_NAME";  
  12.     sqlQueryOcc += " having count(*)>1";  
  13.     sqlQueryOcc += " order by child.PARENT_CODE asc";  
  14.   
  15.     seledItems = ConvertLib.ToStr(Request.Form["sel_items[]"], string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);  
  16.     HiddenField1.Value = String.Join(",", seledItems);  
  17.     using (SqlCommand cmd = new SqlCommand(sqlQueryOcc))  
  18.     {  
  19.         cmd.CommandType = CommandType.Text;  
  20.         cmd.Connection = conn;  
  21.         conn.Open();  
  22.         SqlDataAdapter da = new SqlDataAdapter(cmd);  
  23.         DataTable dt = new DataTable();  
  24.         da.Fill(dt);  
  25.   
  26.   
  27.         foreach (DataRow row in dt.Rows)  
  28.         {  
  29.             builder.AppendFormat("<li><span><input type='checkbox' name='sel_items[]' value='{0}-{3}'{2} /></span>{1}</li>", row["CODE"].ToString(), row["TITLE"].ToString(), this.IsChecked(row["CODE"].ToString(), seledItems), row["PARENT_CODE"].ToString());  
  30.         }  
  31.         conn.Close();  
  32.   
  33.         this.occList.Text = builder.ToString();  
  34.     }  

For ex: DropdownList first item Fruit, when i was select fruit will be show apple, banana, orange, then i select apple and banana. After selected thats change dropdownlist second item for ex: Computer. then when i was select computer will be show keyboard, monitor, mouse, camera etc. and will be select monitor and keyboard. Then i done this submit this event need to show apple, banana, monitor and keyboard.

how can i make it ?

 
 
Answers (2)