获取中继器的物品

发布于 2024-07-25 20:10:23 字数 467 浏览 1 评论 0原文

我试图在页面移动(分页)之前获取中继器项目的所有中继器选定复选框,并将它们存储在某个位置。

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

问题是我从哪里调用这个函数? 我尝试从 ObjectDataSource1_Selected (我使用 objectdatasource 填充中继器)和 ObjectDataSource1_Selecting 调用它,但 rpt.Items.Count 也是 0。

rpt_PreRender() 事件,返回正确的项目数,但它发生在选择复选框之前,而不是后。

我能做些什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼前雾蒙蒙 2024-08-01 20:10:23

您正在寻找的方式是不可能的...请尝试使用此代码...

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

            }
        }
    }

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

            }
        }
    }
揪着可爱 2024-08-01 20:10:23

Repeater 没有内置分页(如 GridView 或其他复杂控件),因此它不提供诸如 PageIndexChanging 等事件。 因此,我假设您有自己的页面导航实现。 因此,您应该调用您在该实现的函数中提供的函数。

如果问题与分页无关,我会简单地建议 ItemDataBound/ItemCreated 事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文