Click here to Skip to main content
16,013,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I have a one `dropdownlist` and `checkbox` items. How can i make when i keep selected items change dropdown listitem.


C#
protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlList.AppendDataBoundItems = true;
        StringBuilder builder = new StringBuilder();
        string sqlQueryOcc = "";
        sqlQueryOcc += " select child.CODE,child.TITLE,child.PARENT_CODE,child.YEARS, parent.INDUS_CAT_NAME";
        sqlQueryOcc += " from SALARY_INDS_OCCNAME as parent ";
        sqlQueryOcc += " inner join dbo.SALARY_INDS_OCCSUBNAME as child ";
        sqlQueryOcc += " on parent.INDUS_CAT_CODE = child.PARENT_CODE";
        sqlQueryOcc += " where child.PARENT_CODE = '" + ddlList.SelectedValue + "' and child.YEARS = '" + ddlYear.SelectedValue + "'";
        sqlQueryOcc += " group by child.CODE,child.TITLE , child.PARENT_CODE ,child.YEARS, parent.INDUS_CAT_NAME";
        sqlQueryOcc += " having count(*)>1";
        sqlQueryOcc += " order by child.PARENT_CODE asc";
    
        seledItems = ConvertLib.ToStr(Request.Form["sel_items[]"], string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        HiddenField1.Value = String.Join(",", seledItems);
        using (SqlCommand cmd = new SqlCommand(sqlQueryOcc))
        {
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
    
    
            foreach (DataRow row in dt.Rows)
            {
                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());
            }
            conn.Close();
    
            this.occList.Text = builder.ToString();
        }
    }


What I have tried:

C#
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 ?
Posted
Comments
Karthik_Mahalingam 22-May-16 4:07am    
are you saving those (checked) values in post back?
ekremtapan 22-May-16 5:36am    
yes ~
Karthik_Mahalingam 22-May-16 5:40am    
are you able to get those checked values in post back, i have a doubt that, you might lose the data on post back.
ekremtapan 22-May-16 5:44am    
so i asking for u how can i keep checked values in checkboxlist.?
Karthik_Mahalingam 22-May-16 5:46am    
first you tell me, are you getting the values in post back (cs), button click event..
based on that only we can find a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900