[英]How do I setup a multi value dropdownlist from a list collection
How to setup a multi value dropdownlist from a list collection... 如何从列表集合中设置多值下拉列表...
Datasource: Listcollection which contains ColorCode and Description... 数据源:Listcollection,其中包含ColorCode和Description ...
how to I setup a dropdown with Colorcode-Description like ORG-orange... 如何使用Colorcode-Description(如ORG-橙色)设置下拉菜单...
then how to capture these selected value as colorcode only by removing description for update purpose... 然后如何仅通过删除更新描述来捕获这些所选值作为颜色代码...
Now I am doing like this... 现在我正在做这样的...
ddl.datesource=list<datasetvalues> // ...contains (colorcode, description)
ddl.DataTextField = "ColorCode";
ddl.DataValueField = "ColorCode";
ddl.databind();
then selected value should be like this... 那么选择的值应该是这样的...
ddlcolor.Items.FindByValue((DataBinder.Eval(formView1.DataItem,
"colorCode").ToString())).Selected = true;
for update: 更新:
ClassA.Color= ddl.selectedvalue();
Now what I need change to in the above code to get the combination of both..otherwise i need have textbox for description which syncs with ddl..which is bit complex for my level of programming...thanks.. 现在,我需要在上面的代码中进行更改以获取两者的组合。否则,我需要具有与ddl同步的描述文本框..对于我的编程水平来说有点复杂...谢谢。
There are a couple of solutions as per my knowlege. 据我所知,有几种解决方案。
1) You can concatenate the text like : Code + "-" + Value, while preparing the list using a For/Foreach... loop 1)您可以在使用For / Foreach ...循环准备列表的同时,连接文本:Code +“-” + Value
2) If it is permitted as per your project, you may also consider overriding the string inside the entity but the selected value will be with a hyphenated(with a - inbetween code & value) string, which you need to string split in the code behind. 2)如果您的项目允许这样做,您也可以考虑覆盖实体内部的字符串,但是所选值将带有连字符(在代码和值之间-),您需要在代码中对字符串进行拆分背后。
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<CodeValue> colors = new List<CodeValue> {new CodeValue{Code="",Value="Select"},new CodeValue{Code="RD",Value="Red"},
new CodeValue{Code="BL",Value="Blue"}};
ddlColors.DataSource = colors;
ddlColors.DataBind();
}
}
protected void btnClick_Click(object sender, EventArgs e)
{
var item = ddlColors.SelectedValue;
var code = item.Split('-');
}
}
class CodeValue
{
public string Code { get; set; }
public string Value { get; set; }
public override string ToString()
{
return this.Code + "-" + this.Value;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.