嵌套转发器在标头模板中传递值

发布于 2024-08-24 21:49:47 字数 1030 浏览 4 评论 0原文

我有一个嵌套的中继器,我想在其标头中传递值。到目前为止,这是我的代码.. 主要问题是标头模板中的控件 ID 也来自代码隐藏。

<asp:Repeater ID="RptrProgCategory" runat="server">
    <ItemTemplate>
        <asp:Repeater ID="RptrPrograms" runat="server">
            <HeaderTemplate><input type="hidden" id="<%= questvalue%>"/></HeaderTemplate>
            <ItemTemplate>                      
                <a href="/" id="catid" class="off"><%# DataBinder.Eval(Container.DataItem, "cat") %></a>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

我希望从代码隐藏中获得 questvalue 的价值。知道如何实现这一目标吗?

编辑:我想将此值放入 DataTable 中并将该值绑定到 Repeater 中,因为我希望这样的输出可能是 <%# DataBinder.Eval(Container.DataItem, "questvalue") %> ;而不是 <%= questvalue%>..但在这种情况下我无法找到控件

Category1(id of hidden field )
  subcat1
  subcat2
  subcat3
Category2(id of hidden field)
  subcat4
  subcat5..and so on..

I have a nested repeater and i want to pass value in its header. Here is my code so far..
The main problem is the id of the control in header template is also coming from code behind.

<asp:Repeater ID="RptrProgCategory" runat="server">
    <ItemTemplate>
        <asp:Repeater ID="RptrPrograms" runat="server">
            <HeaderTemplate><input type="hidden" id="<%= questvalue%>"/></HeaderTemplate>
            <ItemTemplate>                      
                <a href="/" id="catid" class="off"><%# DataBinder.Eval(Container.DataItem, "cat") %></a>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

I want value in questvalue from code behind. Any idea how to achieve this?

Edit: I wanted to put this value in a DataTable and bind that value in Repeater bcoz i want output like this may be <%# DataBinder.Eval(Container.DataItem, "questvalue") %> instead of <%= questvalue%>..but in tht case i am not able to find the control

Category1(id of hidden field )
  subcat1
  subcat2
  subcat3
Category2(id of hidden field)
  subcat4
  subcat5..and so on..

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

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

发布评论

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

评论(2

自由如风 2024-08-31 21:49:52

将转发器中控件的 id 设置为类似 mycontrolId 的内容 - 然后在 OnItemDataBound - (甚至 OnItemCreated)上使用 findcontrol("mycontrolId") - 然后将控件的 id 更改为您的 questvalue 参数。

set the id of the control in the repeater to something like mycontrolId - and then on OnItemDataBound - (or even OnItemCreated) use findcontrol("mycontrolId") - and then change the id of the control to your questvalue param.

话少心凉 2024-08-31 21:49:51
Repeater mainRepeater = this.Page.FindControl("RptrProgCategory") as Repeater;
Repeater nestedRepeater = mainRepeater.FindControl("RptrProgCategory") as Repeater;

然后,您可以在nestedRepeater 中为questValue 执行FindControl。
将 runat='server' 添加到 questvalue 中,以便您可以在后面的代码中访问它。

我凭记忆写下这篇文章,语法可能不正确,但它应该能让你朝着正确的方向前进。

Repeater mainRepeater = this.Page.FindControl("RptrProgCategory") as Repeater;
Repeater nestedRepeater = mainRepeater.FindControl("RptrProgCategory") as Repeater;

You can then do a FindControl in nestedRepeater for questValue.
Add a runat='server' to questvalue so that you can access it in code behind.

I am writing this from memory, syntax might not be correct but it should get you off in the right direction.

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