How to get data from a Bulletedlist in Codebehind ASP.NET?

Asked

Viewed 96 times

2

I have a list of items defined through a Bulletedlist on an Asp.net. page This list is populated with multiple items through attributes DataSource, DataTextField, DataValueField and the method DataBind() in Codebehind in C#.

I need the user to be able to reorder the items in that list and then the page can save that new sorted list instead of the old list. For this, I implemented the Sortable of jQuery, following these two links: [1] and [2].

So far so good, everything is working normally. However, when saving, I need to get this list back (more precisely, the values of DataValueField), to save the changes, and this is my question: how could I get those values back on Codebehind?

Obs.: for some reason I do not have access to the methods GetData() and GetDataSource(), what could help in this matter.

1 answer

1

You can use the property Items, will be something like

for (int i=0; i<BULLETEDLIST.Items.Count; i++) {
         if (BULLETEDLIST.Items[i].Selected)
            RETURN;
      }

In place of return you place the logic of your code, you can create an array and save in that array the items according to the current positions.

  • This is a good approach to getting items from the sorted list, but it does not work when items are reordered. In this case, it returns the same list, even if the order of the list is changed.

  • But he’s not taking back the initial list because of PostBack ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.