Get Repeater's Items

故事扮演 提交于 2019-12-07 14:08:57

问题


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?


回答1:


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)
            {

            }
        }
    }



回答2:


The Repeater does not have built-in Pagination (like the GridView or other complex controls) so it does not offer events such as the PageIndexChanging. I assume therefore, that you have your own Page navigation implementation. You should therefore call the function you have presented within that implemented function.

If the question was unrelated to Paging, I'd have simply suggested the ItemDataBound/ItemCreated events.



来源:https://stackoverflow.com/questions/1054674/get-repeaters-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!