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

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

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:
    1,999
    Ed Allan
    Aug 1, 2003
  2. Froefel

    Postback and databinding question

    Froefel, Aug 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    378
    Andrew Robinson
    Aug 30, 2007
  3. jobs
    Replies:
    0
    Views:
    1,677
  4. Oleg
    Replies:
    1
    Views:
    2,880
    bruce barker
    Sep 25, 2009
  5. Earl Teigrob
    Replies:
    1
    Views:
    422
    Shravan
    Mar 1, 2004
Loading...

Share This Page