[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

server side code to move list items

Posted on 2005-04-22
2
Medium Priority
?
263 Views
Last Modified: 2010-08-05
Hi all,

I need server side code to move the items in alist box up/down based on button clicks.

Thanks
Rama
0
Comment
Question by:smrlnarisetty
2 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 13848598
you mean ASP.NET?
0
 
LVL 13

Accepted Solution

by:
dungla earned 1500 total points
ID: 13855862
I think this will help you

private void btnUp_Click(object sender, System.EventArgs e)
{
      // get selected item of list
      ListItem li = lbItems.SelectedItem;
        if (li == null)
            return;
      int index = lbItems.SelectedIndex;
      // first item cannot be moved up
      if (index <= 0)
            return;
      else
      {
            // swap two items
            lbItems.Items.RemoveAt(index);
            lbItems.Items.Insert(index - 1, li);
      }
}

private void btnDown_Click(object sender, System.EventArgs e)
{
      // get selected item of list
      ListItem li = lbItems.SelectedItem;
        if (li == null)
            return;
      int index = lbItems.SelectedIndex;
      // last item cannot be moved down
      if (index >= lbItems.Items.Count - 1)
            return;
      else
      {
            // swap two items
            lbItems.Items.RemoveAt(index);
            lbItems.Items.Insert(index + 1, li);
      }
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 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