Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > repeater and databinding (postback)

Reply
Thread Tools

repeater and databinding (postback)

 
 
tarscher@gmail.com
Guest
Posts: n/a
 
      10-11-2006
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

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      10-11-2006
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

--
http://www.openmymind.net/
http://www.codebetter.com/


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeater DataBinding on PostBack and base.DataBind() Oleg ASP .Net 1 09-25-2009 03:37 AM
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
Nested repeater databinding question Ed Allan ASP .Net 0 08-01-2003 01:10 PM



Advertisments