c# - 如何在代码隐藏 C# 中将参数从 Repeater 传递给 UserControl

标签 c# user-controls repeater

我需要遍历集合并将值传递给 UserControl。它是动态的,我不知道如何传递参数值。我正在使用中继器。

<asp:Repeater runat="server" id="Repeater1">
  <ItemTemplate>
     <uc1:testControl ID="testControl1" runat="server"   />
  </ItemTemplate>
</asp:Repeater>

在后面的代码中:

Repeater1.DataSource = _myCollection;
                Repeater1.DataBind();

任何帮助将不胜感激!谢谢

最佳答案

ASPX代码:

<asp:Repeater runat="server" id="Repeater1" OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate> 
        <uc1:testControl ID="testControl1" runat="server" /> 
    </ItemTemplate > 
</asp:Repeater>

代码隐藏:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    testControl ctrl = e.Item.FindControl("testControl1") as testControl;

    if (ctrl != null)
        ctrl.MyParameterName = "Foo";
}

关于c# - 如何在代码隐藏 C# 中将参数从 Repeater 传递给 UserControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4903321/

相关文章:

c# - int 是枚举的支持类型

c# - 想要直观地表示原始信息

winforms - 如何在Visual Studio中创建像解决方案资源管理器这样的控件?

user-controls - 银光2.0 : Determine if a dependency property is set before changing it

c# - 如何从代码隐藏的转发器控件中获取整行?

c# - IIS 输出缓存 - 如何将资源添加到缓存,无论路径如何

c# - 在 C# 中检索另一个进程的内存使用情况

用于在不同程序集中定义的类型的 WPF 工具箱安装程序

c# - 我想删除转发器中的行

c# - 如何在 Gridview/Repeater 中保持回发时的滚动位置