如何让第一个组合框输入空白? [英] How to make first combo box entry blank?

查看:64
本文介绍了如何让第一个组合框输入空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用DropDownList在HTML中创建select / option标签如何制作第一个选项

是一个空白字符串?


我有可选值的字段。目前我正在通过

填充DropDownList来查询表中的选项列表。但是表格不应该有一个空行。


几种可能性:


1)使用UNION查询。我在MS Access中使用组合框完成了这个操作,并且union的第一个

成员返回一行。我不记得

的SQL语法返回不是来自表的单行。任何人都知道怎么做?


2)在没有绑定结果集的情况下填充CodeBehind中的DropDownList。只需添加一个

空白行,然后对具有实际行的数据集进行foreach并添加所有行。


3)其他一些方法?

解决方案

#1要求你的数据层知道演示文稿,这样就可以了。


# 2工作正常,并会用oldskool纯粹主义者和php

孩子给你积分,但与...相比这是额外的工作...


#3从数据库中获取数据集并在其中加入一行额外的行

绑定之前:

private void PopulateFamilyList()

{

DataSet ds = Family.List();

ds.Tables [0] .Rows.InsertAt(ds.Tables [0] .NewRow(),0);

DataView dv = ds.Tables [0] .DefaultView;

dv.Sort = Family.Columns.FamilyName;


selFamilyID.DataSource = dv;

selFamilyID.DataValueField = Family.Columns.FamilyID;

selFamilyID.DataTextField = Family.Columns.FamilyName;

selFami lyID.DataBind();

}

祝你好运!


Jason Kester

外籍软件咨询服务
http://www.expatsoftware.com/


---

获取自己的旅游博客,包括行程地图和照片!
http://www.blogabond.com/


数据绑定后, DropDownList.Items.Inser(0,"")


" Randall Parker" < NOtechieSPAMpundit_please @ future_avoidjunk_pundit .com>

在消息新闻中写道:%2 **************** @ tk2msftngp13.phx.gbl ...

使用DropDownList在HTML中创建select / option标签如何使

第一个选项

是一个空白字符串?


我有可选值的字段。目前我正在通过

填充

DropDownList来查询表中的选项列表。但桌子不应该有一个

空白行。


有几种可能性:


1 )使用UNION查询。我已经在MS Access中使用组合框和

第一个

成员返回单行。我不记得SQL语法

for

返回一个不是来自表的单行。任何人都知道怎么做?


2)在没有绑定结果集的情况下填充CodeBehind中的DropDownList。

只需添加一个

空白行然后在具有实际行的数据集上做一个foreach,并且

添加它们。


3)其他一些方法?


Siva M写道:

数据绑定后,DropDownList.Items.Inser(0,"")




我会建议不要这样做。 DataBound控件有时会在绑定后修改它们后再翻转。


Jason Kester

外籍软件咨询服务
http://www.expatsoftware.com/


Using DropDownList to create select/option tags in HTML how to make the first option
be a blank string?

I have fields with optional values. Currently I''m populating the DropDownList by
querying out a list of choices from a table. But the table shouldn''t have a blank row.

A couple of possibilities:

1) Use a UNION query. I''ve done this in MS Access with combo boxes and the first
member of the union returns a single row. I can''t remember the SQL syntax for
returning a single row that is not from a table though. Anyone know how?

2) Populate the DropDownList in CodeBehind without a bind of a result set. Just add a
blank row and then do a foreach on the dataset that has the real rows and add all them.

3) Some other approach?

解决方案

#1 requires your datalayer to know about presentation, so that''s out.

#2 works fine, and will score you points with oldskool purists and php
kids, but it''s extra work compared to...

#3 get your dataset from the database and cram an extra row into it
before binding:
private void PopulateFamilyList()
{
DataSet ds = Family.List();
ds.Tables[0].Rows.InsertAt(ds.Tables[0].NewRow(), 0);
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = Family.Columns.FamilyName;

selFamilyID.DataSource = dv;
selFamilyID.DataValueField = Family.Columns.FamilyID;
selFamilyID.DataTextField = Family.Columns.FamilyName;
selFamilyID.DataBind();
}
Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/


After data binding, DropDownList.Items.Inser (0, "")

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Using DropDownList to create select/option tags in HTML how to make the
first option
be a blank string?

I have fields with optional values. Currently I''m populating the
DropDownList by
querying out a list of choices from a table. But the table shouldn''t have a
blank row.

A couple of possibilities:

1) Use a UNION query. I''ve done this in MS Access with combo boxes and the
first
member of the union returns a single row. I can''t remember the SQL syntax
for
returning a single row that is not from a table though. Anyone know how?

2) Populate the DropDownList in CodeBehind without a bind of a result set.
Just add a
blank row and then do a foreach on the dataset that has the real rows and
add all them.

3) Some other approach?


Siva M wrote:

After data binding, DropDownList.Items.Inser (0, "")



I''d recommend against this. DataBound controls flip out sometimes when
you modify them after binding.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/


这篇关于如何让第一个组合框输入空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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