数据集的下拉列表绑定无法选择特定的SelectedValue [英] Dropdown List bind from DataSet can't select specific SelectedValue

查看:106
本文介绍了数据集的下拉列表绑定无法选择特定的SelectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,

我在asp.net中创建了一个下拉列表,该下拉列表将通过使用数据集从数据库中获取数据.这是从datatset获取的代码.

Hi all expert,

I create one dropdownlist in asp.net and this dropdownlist will get data from database by using dataset. here is the code from get from datatset.

TEST.Service ats = new TEST.Service();
DataSet dset =TEST.GetCustomerList();
this.tcustomer.DataSource = dset;
this.tcustomer.DataTextField = "name";
this.tcustomer.DataValueField = "code";
this.tcustomer.DataBind();


对于此代码,它将在下拉列表中显示所有客户代码和名称,默认客户名称将是第一个(客户A).
当我选择客户E时,我将鼠标移开后,下拉列表将自动选择到客户A.
我的问题是如何从下拉列表中选择任何值,而不选择第一个值?

谢谢

TONY


For this code, it will display all customers code and name into dropdownlist and the default customer name will be the first one(Customer A).
when i select customer E, the dropdownlist will automatic select to Customer A after i leave my mouse from it.
My question is How can i select any value from dropdownlist and it not select the first values?

Thanks

TONY

推荐答案

这些代码在哪里?它们应该在下面的代码中

Where are these codes? They should be in the code as below

if (! IsPostBack)
{

   //  first time the page is loaded.

}


尝试此代码

Try this code

ds = BFField.BFActionCombo(CField);
dt = ds.Tables[0];
ddlAction.DataSource = dt;
ddlAction.DataValueField = dt.Columns["Value"].ToString();
ddlAction.DataTextField = dt.Columns["Description"].ToString();
ddlAction.DataBind();
ddlAction.Items.Insert(0, new ListItem("--- Select ---", "0"));


这篇关于数据集的下拉列表绑定无法选择特定的SelectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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