如何将下拉选择的值设置为零 [英] how to set drop down selected value to zero

查看:141
本文介绍了如何将下拉选择的值设置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个从我要检索值的地方下拉菜单(例如下拉菜单.选定的值).但是我想将其值设置为零(这种情况下,我将不会从下拉菜单中选择任何项目).但是该值来自此从另一个表中删除.因此在将其值保存为零的同时会引发异常,因为在当前表中它是外键.因此如何将其值设置为零

解决方案

对于您要查询的内容,您无需将其设置为零...,因为这也不是外键的有效值.

您需要具有一些实际存在的价值.在这种情况下,您可能会拥有默认/虚拟外键记录,然后在未选择任何内容时传递此键值. < pre lang ="sql"> SELECT&#39; 0&#39;作为Userid,&#39; SELECT&#39; AS FirstName UNION ALL SELECT userid,FirstName from User_Mst


或设置DropDownList控件的属性

追加数据绑定项为true


只要不选择任何内容,只需传递null即可设置数据库字段.确保您表中的该字段接受空值

Hello All,
I have a drop down from where i am retrieving value.(Like drop down. selected value).but I want to set its value to zero(case when i will not select any item from drop down).But the value coming from this drop down from another table.so while saving its value to zero it arrases exception because in current table it is a foreign key.so how to set its value to zero

解决方案

For what you are asking, you don''t need to set it to ZERO... as that too wont be a valid value of Foreign Key.

You need to have some value that actually exists. Might be you can have a default/dummy Foreign Key record for such scenario and then pass this key value whenever nothing is selected.


Select data using
<pre lang="sql">SELECT &#39;0&#39; as Userid,&#39;SELECT&#39; AS FirstName UNION ALL SELECT userid,FirstName FROM User_Mst


or set propery of DropDownList control

appenddatatbounditems as true</pre>


Just pass null for database field to be set whenever there is nothing selected. make sure this field in your table accepts null


这篇关于如何将下拉选择的值设置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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