Last post Jan 21, 2017 08:43 AM by oned_gk
Jan 16, 2017 05:15 PM|SerraDemir|LINK
There is a dropdownlist control in Formview EditTemplate. Formview databounded TblPersonal.And I want update a personal data info with dropdownlist items.,
So DropdownList databounded another table which is TblCountry from DB.
There is no problem here.
And Dropdownlist binding "SelectedValue='<%# Bind("TblPersonal_Field") %>"
So , " Has a SelectedValue element that is not valid because it is not in the list of items."
Formview databounded a database table and dropdownlist databounded different table. And Dropdownlist selected item update formview bounded table. :(
Thanks for your help..
Jan 17, 2017 12:42 AM|oned_gk|LINK
The Main problem is the data you want to edit have "x" country, and country table has "a", "b", "c","d" country.
Ensure that all country values in TblPersonal always exist in country table.
To avoid error for blank country value you can do like this
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
<asp:ListItem>No country selected</asp:ListItem>
Jan 17, 2017 07:34 AM|Cathy Zou|LINK
From your description, I am unable to make sure what is your problem
Would you please provide us with some code about your problem or more detailed description?
Jan 17, 2017 12:24 PM|SerraDemir|LINK
There is a formview which is datasource TblPersonal. And this table has Personal Department Info. If personal want to change his departmant info,he is clicking Update button. It goes to FormViewEdit mode.
In FormviewEdit mode,there is a Dropdownlist control which is databinding TblPersonal Departmant Field.(Single data from Personal ID) Current record is shown DropDownList1 first item.
DropDownList DropdownList1= (DropDownList)FormView1.FindControl("DropdownList1");
var KurumSorgu = (from t in Model.TblPersonal
where t.TCVN == Session["TCVN"].ToString()
DropdownList1.Items.Insert(0, new ListItem(KurumSorgu.Kadro, KurumSorgu.Kadro));
And then , All Departmant names are connected from the TblDepartmant so that the user can see the other departments in the DropDownList control to change info.
var KurumSorguListe = from t in Model.Departmants
where t.KurumIlce == DdlIlce.SelectedValue
DropDownList1.DataTextField = "KurumKunye";
DropDownList1.DataValueField = "KurumKunye";
DropDownList1.DataSource = KurumSorguListe;
At this time,there is no problem.All the data I want to show are shown. Now ;
We binded DropDownList1 in FormView for update the data at TblPersonal,
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Kadro") %>' >
ERROR : "Has a SelectedValue element that is not valid because it is not in the list of items."
Whereas datas are same but different table.
(We can also modify the query as follows: DropDownList control in FormView, connects another table that is not connected to FormView, What to do to retrieve the data from another table and update Formview connected table.)
Jan 21, 2017 06:48 AM|Cathy Zou|LINK
The value coming from <%# Bind("Name") %>, which is passed to the SelectedValue property, does not match an item in its collection. Most likely causes:
1.DropDownList has no items because the evaluation happens before the list gets bound
2.The list is bound but is missing this particular value
3.The value returned could be null
Jan 21, 2017 08:43 AM|oned_gk|LINK
You remove bind("x") selectedvalue.
then in formview databound event, populate the dropdown items, find current value, if exist then select
In formview updating event, get the dropdown selectedvalue to save