Let make the concept right: A
Repeater maintains a
RepeaterItemCol lection which contains 0 or many
RepeaterItem. And each
RepeaterItem is created / rendered based on the
<ItemTemplate > that we defined in the .aspx file.
Let assume that we have a Repeater with a simple structure as:
-
<asp:Repeater runat="server" ID="Repeater1" ...>
-
<ItemTemplate>
-
<asp:Label runat="server" ID="Label1" ... />
-
</ItemTemplate>
-
</asp:Repeater>
-
During runtime, depends on the data source, there may have 0 or many
Label1 being generated in the Repeater. For this reason, the following line is not work:
Repeater1.FindC ontrol("Label1" );
Firstly, there are many
Label1, ASP.NET doesn't know which
Label1 we are asking for. Secondly,
THE CONTEXT IS JUST NOT RIGHT! That's why you get a null all of the time.
Recall that all
RepeaterItem are maintained under the Repeater's
RepaterItemColl ection, and our
Label1 is in fact a control under its particular
RepeaterItem. So, the hierarchy would be:
Repeater --> RepeaterItemCol lection --> RepeaterItem --> Label1
Back to the example: In order to find
Label1 in the 1st RepeaterItem, we should do this:
Repeater1.Items[0].FindControl("L abel1");
In order to retrieve all the
Label1's Text, we should do this:
-
Label lbl;
-
foreach(RepeaterItem i in Repeater1.Items)
-
{
-
lbl = (Label)i.FindControl("Label1");
-
Response.Write(lbl.Text + "<br />");
-
}
-
So, the key point is
THE CONTEXT. I didn't really answer your question. But hope this could help you to understand "where is the right place" to find your HiddenField.
By the way, I am wondering how you would know the right RepeaterItem index so that you can find the exact HiddenField that you want, out of many other HiddenFields in your Repeater.
Consider to use
LinkButton and Repeater's
ItemCommand event if you still can't get your problem solved.