Getting ReorderList Item Values


I customer email me asking how to iterate the values of items in the AJAX Control Toolkit ReorderList Sample.

Thanks to Shawn Burke for the hints. 

Here is how you get to them.

Assuming an Item template that includes 2 label controls…..

 

    1     Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

    2         Dim l1, l2 As Label

    3         Dim i, max As Integer

    4 

    5         Label3.Text = “”

    6         max = ReorderList1.Items.Count – 2

    7         For i = 0 To max

    8             l1 = CType(ReorderList1.Items(i).FindControl(“Label1”), Label)

   09             l2 = CType(ReorderList1.Items(i).FindControl(“Label2”), Label)

   10             Label3.Text = Label3.Text + ”  “ + l1.Text + ”  “ + l2.Text + “<br />”

   11         Next i

   12     End Sub

Comments (1)

  1. Satish says:

    Very easy

    Generate the event handler for ItemDataBound event of the reorderlist

    protected void rlReorderlistItems_ItemDataBound(object sender, ReorderListItemEventArgs e)

       {

           ReorderList rlItems = (ReorderList)sender;

           foreach (ReorderListItem rlItem in rlItems.Items)

           {

               DataList dlItem = rlItem.FindControl("dlItems") as DataList;

               dlItem.DataSource = lstItems;

               dlItem.DataBind();

           }

       }

    Use the rlItem.FindControl("ControlID") to find any control inside the item template.