repeater and databinding (postback)

Discussion in 'ASP .Net' started by tarscher@gmail.com, Oct 11, 2006.

  1. Guest

    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
     
    , Oct 11, 2006
    #1
    1. Advertisements

  2. 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/


    <> wrote in message
    news:...
    > 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
    >
     
    Karl Seguin [MVP], Oct 11, 2006
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ed Allan

    Nested repeater databinding question

    Ed Allan, Aug 1, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,114
    Ed Allan
    Aug 1, 2003
  2. =?Utf-8?B?THVkbWFs?=

    XML DataBinding to the Repeater Control;

    =?Utf-8?B?THVkbWFs?=, Apr 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,219
    =?Utf-8?B?THVkbWFs?=
    Apr 5, 2004
  3. =?Utf-8?B?bXVzb3NkZXY=?=

    Repeater DataBinding - moving the Data forward

    =?Utf-8?B?bXVzb3NkZXY=?=, Apr 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    955
    =?Utf-8?B?bXVzb3NkZXY=?=
    Apr 2, 2006
  4. hazz
    Replies:
    0
    Views:
    632
  5. Froefel

    Postback and databinding question

    Froefel, Aug 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    490
    Andrew Robinson
    Aug 30, 2007
  6. jobs
    Replies:
    0
    Views:
    2,415
  7. Oleg
    Replies:
    1
    Views:
    3,417
    bruce barker
    Sep 25, 2009
  8. Earl Teigrob
    Replies:
    1
    Views:
    684
    Shravan
    Mar 1, 2004
Loading...