Obtain Data from Populated Repeater

M

madfisher

Hi,

I am trying to extract the data from a repeater after a post.

This is my repeater.

<asp:Repeater ID="PreviousBuilds" Runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "BuildNumber")
%></td>
</tr>
</ItemTemplate>
</asp:Repeater>

How can I get the values of "BuildNumber" from within my C# Code from
the repeater?


Thanks

Marcus de Leon
 
K

Karl Seguin [MVP]

Place it inside a label, such as

<asp:label id="BuildNumber" runat="server">
<%# DataBinder.Eval(Container.DataItem, "BuildNumber") %>
</asp:label>

and then you can loop through the items of your repeater and get the label
(and it's value)

foreach item as RepeaterItem in PreviousBuilds.Items
if item.ItemType = ListItemType.Item orelse item.ItemType =
ListItemType.AlternatingItem then
dim label as Label = ctype(item.FindControl("BuildNumber"), Label)
'you can get the buildnumber for this row from label.Text
end if
next

Karl
 
M

madfisher

Hi,

Thanks for your help.

I did this and I am getting empty strings for the label.Text value. Is
there anything else I need to do?
 
M

madfisher

I haven't changed anything in the viewstate. Would that be enabled by
default?
 
K

Karl Seguin [MVP]

Yes, if you don't have EnableViewState="False" on the control or any parent
(including the page) it ought to be on by default.

You are doing this is a button's event handler, right? And you aren't
rebinding (ie, you are only calling DataSource and DataBind() if
!Page.IsPostBack)

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top