数据绑定DropDown控件在.Net [英] Databinding DropDown Control in .Net

查看:163
本文介绍了数据绑定DropDown控件在.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用db实体绑定下拉列表。

I am binding the dropdown with db entity.

ddlCustomer.DataSource = Customer.GetAll();
ddlCustomer.DataTextField = "CustomerName";
ddlCustomer.DataBind();

我想在下拉列表中添加SELECT作为第一个项目列表,然后将实体绑定到下拉列表中。我该怎么做?

I want to add "SELECT" as the first itemlist in dropdown and bind then entity to the dropdown. How can i do this?

推荐答案

添加:

ddlCustomer.Items.Insert(0, "SELECT");

ddlCustomer.DataBind();

After ddlCustomer.DataBind();

数据绑定后,必须插入该项,因为数据绑定清除项。

The item must be inserted after the data bind because the data bind clears the items.

这篇关于数据绑定DropDown控件在.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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