gpt4 book ai didi

c# - 如何在中继器内获取标签而不是在 itemdatabound 中

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:09 28 4
gpt4 key购买 nike

我试图在“for”循环中获取中继器内的标签,但我一直收到错误提示:

"An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code

Additional information: Index was out of range. Must be non-negative and less than the size of the collection."

这是我的代码:

for (var i = 0; i < dt.Rows.Count; i++)
{
Label AppAmmount = (Label)rpOffers.Items[i].FindControl("AppAmmount");
}

最佳答案

您正在循环 dt.Rows.Count 但您正在访问 rpOffers.Items。看起来 DataTable 包含的行数比转发器多。

但为什么不是一个简单的foreach呢?

foreach(RepeaterItem item in rpOffers.Items)
{
Label AppAmmount = (Label)item.FindControl("AppAmmount");
}

关于c# - 如何在中继器内获取标签而不是在 itemdatabound 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45796729/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com