与下拉列表相关 [英] related to dropdownlist

查看:68
本文介绍了与下拉列表相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将多个datatextfield绑定到asp.net中的dropdownlist

how to bind more then one datatextfield to dropdownlist in asp.net

推荐答案

public class Data
    {
        public int Id { get; set; }
        public string Col1 { get; set; }
        public string Col2 { get; set; }
        public string Col3 { get; set; }

    }

var data = List<data>();

var dropdownData = data.Select(x=>new {Id = x.Id, Value = x.Col1+ "|" + x.Col2 + "|" + x.Col3}).ToList();

DropdownList.DataSource = dropdownData;
 DropdownList.DataTextField = "Value";
 DropdownList.DataValueField = "Id";
DropdownList.DataBind();
</data>





您可以创建如上所示的通用列表并将其与下拉列表绑定。

您将获得3个值与Dropdown结合使用|连接。



You can create generic list as displayed above and bind it with dropdown.
You will get 3 values binded with Dropdown concatened with "|".


您可以在sql查询中合并两列,就像您要在下拉列表中显示first_name和last_name一样,您可以使用以下查询。 ..



从tbl_name中选择first_name +''''+ last_name as full_name



现在你可以将full_name绑定到你的dropdown.Hope这将有助于解决你的问题......
You can merge two column in your sql query like if you want to show the first_name and last_name to your dropdown you can use following query...

select first_name + '' '' + last_name as full_name from tbl_name

now you can bind full_nameto your dropdown.Hope this will help in your problem...


谢谢你们我得到了解决方案....





IList< pm_clientinformation> objPM_ClientInformation = new List< pm_clientinformation>();



//获取objPM_ClientInformation中的信息



foreach( OB_ClientInformation f in objPM_ClientInformation)

{

string text = string.Format({0} {1},

f.PM_cliFirstName。 PadRight(10,''\ u00A0''),

f.PM_cliLastName.PadRight(10,''\ u00A0''));

ddlClientName.Items .Add(new ListItem(text,f.PM_cliId.ToString()));

}
thanks guys i got solution....


IList<pm_clientinformation> objPM_ClientInformation = new List<pm_clientinformation>();

//get information in objPM_ClientInformation

foreach (PM_ClientInformation f in objPM_ClientInformation)
{
string text = string.Format("{0}{1}",
f.PM_cliFirstName.PadRight(10,''\u00A0''),
f.PM_cliLastName.PadRight(10,''\u00A0''));
ddlClientName.Items.Add(new ListItem (text ,f.PM_cliId.ToString()));
}


这篇关于与下拉列表相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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