views:

311

answers:

4

Hello,

I'm not familiar with the asp.net repeater control. I have two columns in the repeater, quantity and sku. On button click, I want to loop through the rows in the repeater and pass in each quantity and sku into a method. How do you get this information in a repeater?

A: 

Client side or server side? Assuming you mean server side, use the repeater's OnItemDataBound event. That will fire once per row, with the data for the row included as a parameter.

Joel Coehoorn
+6  A: 

In the method for the button click:

foreach(RepeaterItem item in repeaterControlID.Items)
{
    var quantity = item.FindControl("quantityControlID");
    var sku = item.FindControl("skuControlID");
}

Or something like that. You could alternatively use the RepeaterItem's Controls property to look through them.

E: my interpretation of your question was: "On the postback caused by a button click, I want to loop through the items in the repeater and pass those values into a method." This will not be applicable to populating the repeater or doing something in client-side javascript.

And of course, MSDN is a great resource for learning how to use various classes, like the Repeater

Sean Nyman
thanks, I looked at MSDN but didn't like the examples.
jumbojs
+1  A: 

It depends on how you are displaying "quantity" and "sku" in your ItemTemplate. If you're using the <%# DataBinder.Eval(Container, "quantity") %> syntax, you can do something like this:

foreach(RepeaterItem item in Repeater1.Items)
         {        
            string quantity = ((DataBoundLiteralControl)item.Controls[0]).Text;
            string sku = ((DataBoundLiteralControl)item.Controls[1]).Text;

         }

It would help though if you could post your ItemTemplate.

womp
A: 

You'll want to "type" your controls too to access its properties...

foreach(RepeaterItem item in this.RptTest.Items){ string DdlTestValue = ((DropDown)item.FindControl("DdlTest")).SelectedValue; string TxtTestValue = ((TextBox)item.FindControl("TxtTest")).Text; }

Solburn