repeater and databinding (postback)

T

tarscher

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",
"string5"};
Repeater1.DataSource = list;
Repeater1.DataBind();
}
}

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
postback.

Help is greatly appreciated.

Thanks in advance
Stijn
 
K

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 ==
ItemType.AlternatingItem)
{
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.

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top