PeteEngineer
asked on
Why my code is replaceing instead of inserting (C#)
Why my code is not inserting at Oth position ...
its just replacing the oth element and start with 2 ..
i am loosing index 1 location
its just replacing the oth element and start with 2 ..
i am loosing index 1 location
ddlLndState.Items.Clear();
Components.Master.State.IState stateEngine = new Components.Master.State.Engine();
List<Components.Master.State.DTO> lstState = stateEngine.ReadAllByRegion(regionId);
lstState.RemoveAt(0);
lstState.Insert(0,new Components.Master.State.DTO() { Id = -1, Name = "All States" });
ddlLndState.DataSource = lstState;
ddlLndState.DataBind();
stateEngine = null;
LstItem = new ListItem("--Select--", "-1");
ddlLndState.Items.Insert(0, LstItem);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lstState.RemoveAt(0); is call before calling Insert.
Can you look at the contents of the List<> in a debugger and, if so, does it contain the information in the expected order? If so then the problem is a failure of the UI element to recognize that its data source has been changed. If so then it may be that your UI element requires explicit notification of a data change, has not been enabled to react automatically or is improperly or incompletely bound.