C# 获取中继器的物品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1054674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Repeater's Items
提问by
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.
问题是我从哪里调用这个函数?我试图从 ObjectDataSource1_Selected(我使用 objectdatasource 来填充转发器)和 ObjectDataSource1_Selecting 调用它,但 rpt.Items.Count 也是 0。
rpt_PreRender() event, returns the right number of items but it happens before the selection of checkboxes and not after.
rpt_PreRender() 事件,返回正确数量的项目,但它发生在选择复选框之前而不是之后。
What can i do?
我能做什么?
采纳答案by Muhammad Akhtar
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)
{
}
}
}
回答by Cerebrus
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.
Repeater 没有内置分页(如GridView
或其他复杂控件),因此它不提供诸如PageIndexChanging
. 因此,我假设您有自己的页面导航实现。因此,您应该调用您在该已实现函数中提供的函数。
If the question was unrelated to Paging, I'd have simply suggested the ItemDataBound/ItemCreated
events.
如果问题与 Paging 无关,我会简单地建议这些ItemDataBound/ItemCreated
事件。