repeater and databinding (postback)



Hi all,

I have a repaeter rendering textboxes. I also attach a datascource
(array) to the repeater with default valeus:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
string[] list = {"string1", "string2", "string3", "string4",
Repeater1.DataSource = list;

A user can change the content of the 5 textboxes and when he clicks the
sublit button I want to read out the data from the textboxes and put it
into a string array:
protected void Button_Click(object sender, EventArgs e)
string[] list = Repeater1.DataSource as string[];

The problem is that the datasource is null and thus also the list
string. I only attach a datasource at not postback. I don't know how I
can attach a datasource, which is the user input to the repeater, at

Help is greatly appreciated.

Thanks in advance

Karl Seguin [MVP]

The DataSource won't survive a postback intact - even with viewstate on.

You need to loop through the Repeater, find each textbox and get it's value.

foreach (RepeaterItem item in Repeater1.Items)
if (item.ItemType == ItemType.Item || item.ItemType ==
TextBox txt = (TextBox)item.FindControl("TextboxId");
//now you can get the txt.Text and do stuff

The above code is just a rough go at it.


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