Datalist 中标签的 ASP.NET 事件处理程序

发布于 2024-07-15 17:33:16 字数 1825 浏览 8 评论 0原文

我正在开发一个 ASP.NET 页面,并且有一个 DataList,其中有一个不可见的标签 ID。 数据列表由查询 A 填充。

我尝试在 VB 代码中添加一个处理程序,它将在 ID 更改后运行查询 B,在项目模板中填充不同的标签。 我想我需要去数据列表中的某个地方,但是通过智能感知和谷歌搜索没有成功。 有谁知道我如何获得该标签? 抱歉,如果这是一个愚蠢的问题,并感谢您的帮助。

编辑:我了解了如何在函数内部访问数据列表项,但是如何仅对事件处理程序中的 DataList 控件的一部分执行此操作? 我看到的所有选项都与涉及数据列表的完整事件相关,而不是单个标签更改。 谢谢。

编辑2:

我想我应该添加一些代码,以更好地解释我遇到的确切问题。

                <asp:DataList ID="DataList1" runat="server" DataSourceID="Omitted,Ilikemyjob">
                <ItemTemplate>
                      <asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("IncdntDate") %>'></asp:Label><br />
                      <asp:Label ID="ToLabel" runat="server" Font-Size="Small" Text='<%# Eval("Roadway") %>'></asp:Label><br />
                      <asp:Label ID = "lblCrossroad" runat ="server" Font-Size = "Small" Text = '<%# Eval("Crossroad") %>'></asp:Label><br />
                      <asp:Label ID = "lblRdwyID" runat ="server" Font-Size="Small" Visible = "false" Text = '<%# Eval ("RdwyID") %>'></asp:Label>
                      <asp:Label ID = "DistanceLabel" runat ="server" Font-Size = "Small" Text = '<%# Eval("RptTime") %>'></asp:Label><br />
                      <asp:Label ID = "lblTTime" runat ="server" Font-Size = "small" visible ="false"></asp:Label>
                      <hr />
                 </ItemTemplate>
            </asp:DataList><br />

我正在做 DataList 的事情,并且我有一个不同的查询,如果 lblRdwyID 设置为某个值范围,我想将其值存储到 lblTTime,但认为它并不总是设置为一个值。

我正在尝试设置一个事件,该事件将在设置 lblRdwyID 时触发,该事件将启动其他查询并设置模板化项目 lblTTime 的值并使其可见。 有没有好的方法可以做到这一点? 我尝试搞乱 DataList1 的事件,但找不到任何东西来实现这一目的。

I'm working on an ASP.NET page, and have a DataList with a non-visible label, ID, inside of it. The Datalist is populated by Query A.

I'm trying to add a handler in my VB code where it will run Query B, populating a different label in the Item Template, after ID is changed. I figure I need to go somewhere in the DataList, but poking through Intellisense and a google search weren't successful. Does anyone know how I get to that label? Sorry if this is a dumb question, and thanks for the help.

Edit: I see how I can access the datalist items while inside the function, but how do I do it for only one part of the DataList control in the Event Handler? All the options I'm seeing are related to full events involving the Data List, not a single label changing. Thanks.

Edit 2:

I figured I'd add some code, to better explain exactly the exact issue I'm having.

                <asp:DataList ID="DataList1" runat="server" DataSourceID="Omitted,Ilikemyjob">
                <ItemTemplate>
                      <asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("IncdntDate") %>'></asp:Label><br />
                      <asp:Label ID="ToLabel" runat="server" Font-Size="Small" Text='<%# Eval("Roadway") %>'></asp:Label><br />
                      <asp:Label ID = "lblCrossroad" runat ="server" Font-Size = "Small" Text = '<%# Eval("Crossroad") %>'></asp:Label><br />
                      <asp:Label ID = "lblRdwyID" runat ="server" Font-Size="Small" Visible = "false" Text = '<%# Eval ("RdwyID") %>'></asp:Label>
                      <asp:Label ID = "DistanceLabel" runat ="server" Font-Size = "Small" Text = '<%# Eval("RptTime") %>'></asp:Label><br />
                      <asp:Label ID = "lblTTime" runat ="server" Font-Size = "small" visible ="false"></asp:Label>
                      <hr />
                 </ItemTemplate>
            </asp:DataList><br />

There's the DataList thing I'm doing, and I have a different query that I want to store the value of to lblTTime if lblRdwyID is set to a certain range of values, thought it will not always be set to a value.

I'm trying to set up an event that will trigger when lblRdwyID is set, that will launch the other query and set the value of that templated items lblTTime and make it visible. Is there a good way to do this? I tried messing around with DataList1's events, but couldn't get anything to do the trick.

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

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

发布评论

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

评论(2

半仙 2024-07-22 17:33:16

如果您的标签将其可见性设置为 false,则它不会在屏幕上呈现(与将可见性设置为隐藏的 div 块相反),所以我打赌这就是为什么您实际上无法在绑定已经发生。

您是否尝试过使用 DataKey 属性来存储 ID? 它可以在行级别轻松访问,并且您可以根据需要存储其他数据。

If your label has its visibility set to false, it won't render on the screen (as opposed to having a div block with visibility set to hidden), and so I wager that is why you can't actually find the control after the binding has occurred.

Have you tried using the DataKey property to store the ID instead? It is easily accessible at the row level and you can store additional data if needs be.

浅紫色的梦幻 2024-07-22 17:33:16

假设您有该行,请使用:

row.FindControl("mylabelid")

Assuming you have the row, you use:

row.FindControl("mylabelid")

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