组合在一个DataTextField两个字段。这可能吗? [英] Combining two fields in a DataTextField. Is this possible?

查看:309
本文介绍了组合在一个DataTextField两个字段。这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集而我绑定到一个列表框。不过,我想结合两个领域,以弥补DataTextField。这是可能的,还是我经历的数据行有循环?

I have a dataset which I am binding to a listbox. However, I want to combine two of the fields to make up the DataTextField. Is this possible, or am I going to have to loop through the Data Rows?

lstAddressDropdown.DataSource = dsAddress;
lstAddressDropdown.DataTextField = "StreetAddress" + "Place";
lstAddressDropdown.DataBind();
lstAddressDropdown.Items.Insert(0, new ListItem("Please select"));

值得注意的是,数据来源于Web服务后面,所以我不能改变任何存储过程来列有结合起来。

It's worth noting that the dataset comes back from a web service so I can't change any stored procedure to combine the columns there.

推荐答案

您可以将附加列添加到这是一个计算列数据表,并用它作为你的datatextfield(的文档:多场数据绑定

You can add an additional column to the datatable that is a computed column and use it as your datatextfield (docs: Multi-field Data Binding).

因此​​,对于你上面的例子,你可以做这样的事情:

So for your example above you could do something like this:

dsAddress.Tables[0].Columns.Add("StreetAndPlace",typeof(string),"StreetAddress + Place");
lstAddressDropdown.DataSource = dsAddress;
lstAddressDropdown.DataTextField = "StreetAndPlace";
lstAddressDropdown.DataBind();
lstAddressDropdown.Items.Insert(0, new ListItem("Please select"));

要添加的StreetAddress与地方之间的空间的StreetAddress +''+地方

To add a space between the StreetAddress and Place replace the expression string shown above with "StreetAddress + ' ' + Place"

这篇关于组合在一个DataTextField两个字段。这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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