本文介绍了如何绑定列表,以一个DDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,我试图将数据添加到DDL。它返回的数据,(namespace.List)。但有件事我很想念......有什么建议?

 公开名单< getBranch>科{获得;私定; }
...
getBranch(用户code);
ddlOption.DataSource =分公司;
ddlOption.DataBind();
 

解决方案

所有你缺少的是要告诉下拉什么性质的getBranch以显示为文本,什么是价值的使用方法:

  ddlOption.DataTextField =propertyOfgetBranchToShowAsText;
ddlOption.DataValueField =propertyOfgetBranchToUseAsValue;
 

确定,这里的code应该是什么样子(我认为):

你的店类的属性:

 公众诠释BranchValue {获取;集;}
公共字符串BranchText {获取;集;}
 

...

 公开名单<店> branchesToShow {获得;私定; }
...
branchesToShow = getBranch(用户code); //获取分支机构的名单
ddlOption.DataTextField =BranchText
ddlOption.DataValueField =BranchValue;
ddlOption.DataSource = branchesToShow;
ddlOption.DataBind();
 

I have a list and I am trying to add the data to the ddl. It returns data, (namespace.List). But there is something I am missing... any suggestions?

public List<getBranch> Branch { get; private set; }
...                           
getBranch(user.code);
ddlOption.DataSource = Branch;                        
ddlOption.DataBind();
解决方案

All you're missing is to tell the dropdown what property of getBranch to show as text and what to use as value:

ddlOption.DataTextField = "propertyOfgetBranchToShowAsText";
ddlOption.DataValueField = "propertyOfgetBranchToUseAsValue";

ok, here's how the code should look like (i think):

your Branch class properties:

public int BranchValue {get;set;}
public string BranchText {get;set;}

...

public List<Branch> branchesToShow { get; private set; }
...                           
branchesToShow = getBranch(user.code); //get the list of branches
ddlOption.DataTextField = "BranchText"
ddlOption.DataValueField = "BranchValue";
ddlOption.DataSource = branchesToShow;                        
ddlOption.DataBind();

这篇关于如何绑定列表,以一个DDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 02:46