如何在asp.net中为下拉列表添加水印 [英] How to watermark a dropdownlist in asp.net

查看:62
本文介绍了如何在asp.net中为下拉列表添加水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何为下拉列表添加水印,以便我可以指示选择名称作为显示的值,但不能将其作为选择发布到数据库。



我尝试过使用没有价值的项目,但无论如何它总是会出现一个值。每当我更新我的页面时,它总会在那里放一个值。所以我为第一选择添加了一个空白项目,但我想在那里选择一个名字。



我尝试了什么:



尝试DropdownList值。

Does anyone know how to watermark a dropdown list so that I can indicate "Select a Name" as the shown value but not have it post to the database as a selection.

I have tried using an item with no value but it keeps coming up with a value anyway, Any time I update my page it always puts a value there. So I add a blank item for the first choice but I want a Select Name there.

What I have tried:

Tried the DropdownList values.

推荐答案

这不是水印。这是一个占位符。 ASP.NET控件不是浏览器处理的特殊内容。 ASP.NET标记,< asp ... 标记,只是告诉视图引擎发出正常的HTML。



现在,没有标准方法可以将占位符添加到下拉列表中。它不在HTML规范中。你可以伪造它,但是你可能想象它不会起作用。最重要的是,占位符支持并非所有浏览器或浏览器版本的标准。



您可以找到一个示例 where [ ^ ]。您可能不得不在ASP.NET中做一些捏造以发出正确的HTML,例如 this [ ^ ]。
That's not a watermark. It's a "placeholder". ASP.NET controls are not some special thing that browsers handle. ASP.NET markup, <asp... tags, just tell the view engine to emit normal HTML.

Now, there is no standard way of adding a placeholder to a dropdown list. It's just not in the HTML spec. You can fake it, but it's not going to work how you're probably imagining it. On top of that, placeholder support isn't standard across all browsers or browser versions.

You can find an example here[^]. You're probably going to have to do some fudging in ASP.NET to emit the correct HTML, like this[^].


这篇关于如何在asp.net中为下拉列表添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆