一般情况之下,DropDownList的DataTextField只是绑定一个列,因系统要求,DropDownList的DataTextField同时绑定多列来显示。如下图:
实现这个并不难,只要在存储过程或SQL语句写好即可。下面实现演示是使用存储过程,两个字段连接为一个,并给它一个别名 ([LName] + N' ' + [FName]) AS [FullName] 。
View Code
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [ dbo ] . [ usp_GetMember ] AS SELECT [ MemberId ] ,( [ LName ] + N ' ' + [ FName ] ) AS [ FullName ] FROM [ dbo ] . [ Member ]
在.aspx.cs绑定:
View Code
protected void Page_Load( object sender, EventArgs e) { if ( ! IsPostBack) { Data_Binding(); } } private void Data_Binding() { Member objMember = new Member (); this .DropDownList1.DataSource = objMember.GetMember(); this .DropDownList1.DataTextField = " FullName " ; // 绑定别名 this .DropDownList1.DataBind(); }