Monday, July 18, 2011

ASP.NET : How to access/read value from any control within a repeater.

We often need to read values from a databound control inside a repeater. How to read the control?

This is very simple. The following code sample has all in it. We assume that the repeater variable is repeaterObj and the control we want to access has the id "controlId". The control resides under itemtemplate. Then the code will be:

repeaterObj.ItemTemplate.Items[0].findControl("controlId");

To read the value from a label use :

string labelText = repeaterObj.ItemTemplate.Items[0].findControl("controlId").Text;