我可以切换超链接和文本框吗?

发布于 2024-08-13 22:09:17 字数 440 浏览 3 评论 0原文

我的 gridview 中有一个数据列,它有一个 url 或纯文本。如何切换 HTML 中的超链接?

这就是我到目前为止所拥有的...返回“查看链接...”,带或不带 url :(

<ItemTemplate>
     <asp:HyperLink ID="HyperLink3" runat="server" Text="View Link..." NavigateUrl='<%# Bind("DocLink") %>' Target="_blank"></asp:HyperLink>
     <asp:Label ID="Label8" runat="server" Text='<%# Bind("Details") %>'></asp:Label>
</ItemTemplate>   

I have datacolumn in my gridview that has either a url, or plain text. How do I toggle a Hyperlink in the HTML?

This is what I have so far... which returns "View Link..." with or without a url :(

<ItemTemplate>
     <asp:HyperLink ID="HyperLink3" runat="server" Text="View Link..." NavigateUrl='<%# Bind("DocLink") %>' Target="_blank"></asp:HyperLink>
     <asp:Label ID="Label8" runat="server" Text='<%# Bind("Details") %>'></asp:Label>
</ItemTemplate>   

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

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

发布评论

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

评论(1

琉璃梦幻 2024-08-20 22:09:17

我不确定我是否理解您的问题,但如果您尝试根据数据有选择地显示或隐藏 ItemTemplate 中的某个控件,请使用 OnItemDataBound 事件,使用 FindControl( ) 获取控件,并适当地设置每个控件的 Visible 属性。

如果您的 Visible 逻辑相对简单,您可以将其直接添加到您的 ItemTemplate 中。像这样的东西:

Visible='<%# ((System.Data.DataRowView)Container.DataItem)["DocLink"] != System.DBNull.Value %>'

I'm not sure I understand your question, but if you are trying to selectively show or hide one of the controls in your ItemTemplate depending on the data, use the OnItemDataBound event, use FindControl() to get the controls, and set the Visible property on each appropriately.

If your logic for Visible is relatively simple, you can add it right to your ItemTemplate. Something like:

Visible='<%# ((System.Data.DataRowView)Container.DataItem)["DocLink"] != System.DBNull.Value %>'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文