Click here to Skip to main content
15,909,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi can any one please me to resolve this issue....that is i'm getting the error as
-----------Error----------------------
{"'DDLShipmentType' has a SelectedIndex which is invalid because it does not exist in the list of items.\r\nParameter name: value"}

------------------------------------------------

near
cmb_ShipmentType.SelectedIndex = 0;
i'm getting the selectedindex as -1 in the below code

C#
public void PopulateShipmentType(DropDownList cmb_ShipmentType)
       {
           string Sql = "select a,b from xxx where NUIsActive=1";
           using (DataView Source = new DataView(objDBLib.ExecuteQuery(Sql).Tables[0]))
           {
               cmb_ShipmentType.DataSource = Source;
               cmb_ShipmentType.DataTextField = "a";
               cmb_ShipmentType.DataValueField = "b";
               cmb_ShipmentType.DataBind();
               
              cmb_ShipmentType.SelectedIndex = 0;
           }
       }
Posted
Updated 15-Jun-16 21:09pm
v2
Comments
Does the source return anything?

1 solution

In your above Situation "Source" doesn't return any rows.
So it can't set a value for SelectedIndex because there is nothing to select.

Check your Table if there are any entries.
 
Share this answer
 

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