如何设置下拉列表DataTextField显示两个数据属性字段? [英] How to set drop down list DataTextField to display two data property fields?

查看:752
本文介绍了如何设置下拉列表DataTextField显示两个数据属性字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉的在代码中填入数据背后列表。在 DataTextField 属性设置为以下代码:

I have a drop down list that is populated with data in the code behind. The DataTextField attribute is set with the following code:

ddlItems.DataTextField = "ItemName";



我想作为 DataTextField 。我试着用下面的代码,但没有奏效。而且我已经研究在网上也没有找到如何使用两个数据的属性。

I want to display two data properties as the DataTextField. I tried using the following code but it didn't work. And I have researched on the net but couldn't find how to use two data properties.

ddlItems.DataTextField = "ItemName" + "ItemDescription";

什么代码,我需要用它来做到这一点?

What code do I need to use to do this?

推荐答案

您可以使用ddlItems的格式化事件,这将让你的逻辑设置如何某个项目转换为字符串,或者如果它使任何意义的使用。你的程序,有这样RepresentingString返回名称+说明,并绑定到该属性的属性。

You can use the Formatting event of ddlItems which will allow you to set logic to how to convert a certain item to a string, or if it makes any sense to use in your program, have a property like RepresentingString that returns Name + Desc, and bind to that property.

通过更多的答案和代码示例类似的问题:
格式DropDownList.TextValue

Similar question with more answers and code examples: Format DropDownList.TextValue

这篇关于如何设置下拉列表DataTextField显示两个数据属性字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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