gpt4 book ai didi

c# - 如何在组合框中设置默认空值

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:39 26 4
gpt4 key购买 nike

dr = new MySqlDataAdapter("select tvl_code, 
concat_ws(',', tvl_code, citi_name) citiname
from code_desc where travel_mode = 'BUS'", conn);
ds1 = new DataSet();
dr.Fill(ds1);
ddlfrom.DataSource = ds1;
ddlfrom.DataTextField = "citiname";
ddlfrom.DataValueField = "tvl_code";
ddlfrom.DataBind();

通过这段代码,我将我的组合框绑定(bind)到数据库,并且我能够从我的数据库中填充组合框。但是当我打开页面时,组合框默认包含一个来自数据库的值..意味着名字来 self 填充的数据库列表显示在组合框上。我想在组合框上显示空白。这意味着它不应该显示任何打印,直到我从下拉列表中选择一些东西。如何做到这一点..??

最佳答案

试试这个:

ddlfrom.Items.Insert(0, "Select...");

像这样:

dr = new MySqlDataAdapter("select tvl_code, concat_ws(',', tvl_code, citi_name) citiname from code_desc where travel_mode = 'BUS'", conn);
ds1 = new DataSet();
dr.Fill(ds1);
ddlfrom.DataSource = ds1;
ddlfrom.DataTextField = "citiname";
ddlfrom.DataValueField = "tvl_code";
ddlfrom.DataBind();
ddlfrom.Items.Insert(0, "Select...");

关于c# - 如何在组合框中设置默认空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19947364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com