将空白值设置为sql中的列,而不在下拉列表中选择值 [英] Set blank value to the column in sql on not selecting a value in drop down list

查看:85
本文介绍了将空白值设置为sql中的列,而不在下拉列表中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有树的下拉列表。在选择树名并按下提交按钮时,相应的id将存储在sql表中。但是我在下拉列表中将default设置为--select--,这意味着没有选择任何值。所以当我点击提交按钮时,什么都不应该存储在sql数据库中。但它存储id 0或--select - 。

Hi,
I have a drop down list for trees. On selecting the tree name and press the submit button, the corresponding id will be stored in the sql table. But I set default as --select-- in the drop down list, this means no value is selected. So when I click submit button nothing should be stored in the sql database. But it stores either id 0 or --select--.

推荐答案

单击提交按钮时首先检查下拉列表的选定值。
Check first the selected value of the dropdown list upon clicking the submit button.


使用DropDownList1.SelectedItem.Text获取所选值。



试试这样:

Use DropDownList1.SelectedItem.Text to get the selected value.

Try like this:
 if( DropDownList1.SelectedItem.Text =="Select")
  {
  DropDownList1.Items.Clear();
 DropDownList1.Items.Insert(00, "Null");
 DropDownList1.SelectedIndex = 0;
 //insert query here (Null)
 }
else
 {
  // insert query here( SelectedItemValue)
 }






or

if (ddltrees.SelectedItem.Text == "Select")
{
//insert query without selected value---------don't pass dropdownlist selected value here
}
else
{
//insert query with selected value ------pass dropdownlist  selected value;<br>
}


这篇关于将空白值设置为sql中的列,而不在下拉列表中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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