Question : dropdown list add a static list item.

I am having problems with a dropdown list that generates a list item based on the items from the database.  It was working at one time and now it is not generating the items.  I would appreciate it if anyone could see if thre is a reason that this is not working now.  If there are records in the SQL query, then those appear in the list, but the list items I am adding are not appearing in the list.

I am including the code below.  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
DataSet dataSet = new DataSet();
               // conn.Open();
                SqlDataAdapter adapter;
                adapter = new SqlDataAdapter(SQL2, conn);
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@DSCRIPTN", strJobTitle));


                adapter.Fill(dataSet, "Jobs");
                int intCount = dataSet.Tables["Jobs"].Rows.Count;

                if (intCount > 0)
                {
                    //Add the None Chosen item and the replacement item to the Available Jobs list
                    drpAvailableJobs.Items.Insert(0, new ListItem("None Chosen", ""));
                    drpAvailableJobs.Items.Insert(1, new ListItem("Replacement", "000000"));
                }
                else
                {
                    //Add No positions availble to the list when there are not records;
                    drpAvailableJobs.Items.Insert(0, new ListItem("No Positions Available", "None"));
                    drpAvailableJobs.Items.Insert(1, new ListItem("Replacement", "000000"));
                    

                }


                drpAvailableJobs.DataSource = dataSet;
                drpAvailableJobs.DataMember = "Jobs";


                
                
                drpAvailableJobs.DataBind();

Answer : dropdown list add a static list item.

The answer to the first question is quite obvious - AppendDataBoundItems - basically appends databound items retaining the exising ones.

For the second part, you basically have to capture the 'OnSelectedIndexChanged' event of the first dropdownlist and in this event, you need to clear the items of the second dropdownlist, something like:

secondDropDownList.Items.Clear();

Arun

Random Solutions  
 
programming4us programming4us