Solved

Why my code is replaceing instead of inserting (C#)

Posted on 2011-09-12
3
251 Views
Last Modified: 2012-05-12
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

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);

Open in new window

0
Comment
Question by:PeteEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36523086
Perhaps because you called lstState.RemoveAt(0); just prior to calling Insert?
0
 

Expert Comment

by:haggard
ID: 36545209
I'm not sure I understand your question. Are you saying that your UI element should be displaying "--Select--" as the first item but is displaying "All States" and that you are expecting that "All States" should be the second element being displayed? If so, maybe you need to call an Update() command of some sort. It is a bit difficult to know for sure since you have not been very precise in the definition of your issue.

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.
0
 
LVL 4

Expert Comment

by:hassanwarraich
ID: 36554487
lstState.RemoveAt(0); is call before calling Insert.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question