Get Repeater's Items

21,961

the way you are looking is not possible...plz try using this code...

if (Repeater1.Items.Count > 0)
    {
        for (int count = 0; count < Repeater1.Items.Count; count++)
        {
            CheckBox chk = (CheckBox)Repeater1.Items[count].FindControl("CheckBox1");
            if (chk.Checked)
            {

            }
        }
    }
Share:
21,961
Admin
Author by

Admin

Updated on October 03, 2020

Comments

  • Admin
    Admin over 3 years

    I am trying to get all repeater's selected checkboxes of repeater's item just before page movement (pagination), and store them in some place.

     foreach (RepeaterItem ri in rpt.Items)
      {        
          CheckBox box = (CheckBox)ri.FindControl("chkBox");
           if (box.Checked)
           {
              ...
           }
      }
    

    The problem is where do i call this function from? I've tried to call it from ObjectDataSource1_Selected (I use objectdatasource to populate repeater) and ObjectDataSource1_Selecting but rpt.Items.Count is also 0.

    rpt_PreRender() event, returns the right number of items but it happens before the selection of checkboxes and not after.

    What can i do?

  • Admin
    Admin almost 15 years
    I can't call it inside my Pagination function because it causes a postback, and postback clears the repeater.
  • Admin
    Admin almost 15 years
    ITemDatabound events work for each item, and i want to do it for all items at once.