My Dropdown List not inserting selected value into database.
-
Sqlds.InsertCommandType = SqlDataSourceCommandType.Text;
Sqlds.InsertCommand = "insert into Population(States,LGA,Males,Females,Bothsexes,Landsize,Terrain,Remarks) values (@countryList,@statelist,@male,@fmale,@bsexes,@landsize,@terrain,@remarks)";
Sqlds.InsertParameters.Add("countryList",countryList.SelectedValue);
Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
Sqlds.InsertParameters.Add("male", male.Text);
Sqlds.InsertParameters.Add("fmale", fmale.Text);
Sqlds.InsertParameters.Add("bsexes", bsexes.Text);
Sqlds.InsertParameters.Add("landsize", landsize.Text);
Sqlds.InsertParameters.Add("terrain", terrain.Text);
Sqlds.InsertParameters.Add("remarks", remarks.Text);
Sqlds.Insert();I am having problem with my dropdownlist, Its not inserting selected values into database only the first value on the list that is inserted into the db. Here is the varable for it. Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
-
Sqlds.InsertCommandType = SqlDataSourceCommandType.Text;
Sqlds.InsertCommand = "insert into Population(States,LGA,Males,Females,Bothsexes,Landsize,Terrain,Remarks) values (@countryList,@statelist,@male,@fmale,@bsexes,@landsize,@terrain,@remarks)";
Sqlds.InsertParameters.Add("countryList",countryList.SelectedValue);
Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
Sqlds.InsertParameters.Add("male", male.Text);
Sqlds.InsertParameters.Add("fmale", fmale.Text);
Sqlds.InsertParameters.Add("bsexes", bsexes.Text);
Sqlds.InsertParameters.Add("landsize", landsize.Text);
Sqlds.InsertParameters.Add("terrain", terrain.Text);
Sqlds.InsertParameters.Add("remarks", remarks.Text);
Sqlds.Insert();I am having problem with my dropdownlist, Its not inserting selected values into database only the first value on the list that is inserted into the db. Here is the varable for it. Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
Which event you have written above code?
-
Sqlds.InsertCommandType = SqlDataSourceCommandType.Text;
Sqlds.InsertCommand = "insert into Population(States,LGA,Males,Females,Bothsexes,Landsize,Terrain,Remarks) values (@countryList,@statelist,@male,@fmale,@bsexes,@landsize,@terrain,@remarks)";
Sqlds.InsertParameters.Add("countryList",countryList.SelectedValue);
Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
Sqlds.InsertParameters.Add("male", male.Text);
Sqlds.InsertParameters.Add("fmale", fmale.Text);
Sqlds.InsertParameters.Add("bsexes", bsexes.Text);
Sqlds.InsertParameters.Add("landsize", landsize.Text);
Sqlds.InsertParameters.Add("terrain", terrain.Text);
Sqlds.InsertParameters.Add("remarks", remarks.Text);
Sqlds.Insert();I am having problem with my dropdownlist, Its not inserting selected values into database only the first value on the list that is inserted into the db. Here is the varable for it. Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
solution: public void Page_Load() { stateList.AutoPostBack = true; }
-
solution: public void Page_Load() { stateList.AutoPostBack = true; }
-
That's right. Another Convenience way: You would Config AutoPostBack in the Property windows of the Dropdownlist.
-
Sqlds.InsertCommandType = SqlDataSourceCommandType.Text;
Sqlds.InsertCommand = "insert into Population(States,LGA,Males,Females,Bothsexes,Landsize,Terrain,Remarks) values (@countryList,@statelist,@male,@fmale,@bsexes,@landsize,@terrain,@remarks)";
Sqlds.InsertParameters.Add("countryList",countryList.SelectedValue);
Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
Sqlds.InsertParameters.Add("male", male.Text);
Sqlds.InsertParameters.Add("fmale", fmale.Text);
Sqlds.InsertParameters.Add("bsexes", bsexes.Text);
Sqlds.InsertParameters.Add("landsize", landsize.Text);
Sqlds.InsertParameters.Add("terrain", terrain.Text);
Sqlds.InsertParameters.Add("remarks", remarks.Text);
Sqlds.Insert();I am having problem with my dropdownlist, Its not inserting selected values into database only the first value on the list that is inserted into the db. Here is the varable for it. Sqlds.InsertParameters.Add("stateList", stateList.SelectedValue);
you are picking the only SelectedValue of dropdownlist, put this thing in foreach or for loop that moves till the items.count is maximum.
- Happy Coding - Vishal Vashishta
-
That's right. Another Convenience way: You would Config AutoPostBack in the Property windows of the Dropdownlist.