datatextfield

How to bind the ASP.NET drop down list DataTextField property to a nested property

帅比萌擦擦* 提交于 2019-12-30 22:55:21
问题 I want to bind the DataTextField property of a ASP.NET drop down control to a property of an object that is a property of the initial data source. How would I accomplish that particular task. Drop down data source data schema public class A { public string ID { get; set; } public B { get; set; } } public class B { public string Name { get; set; } //want to bind the DataTextField to this property } ASP.NET code behind DropDownList MyDropDownList = new DropDownList(); List<A> MyList = GetList()

How to bind the ASP.NET drop down list DataTextField property to a nested property

馋奶兔 提交于 2019-12-30 22:55:14
问题 I want to bind the DataTextField property of a ASP.NET drop down control to a property of an object that is a property of the initial data source. How would I accomplish that particular task. Drop down data source data schema public class A { public string ID { get; set; } public B { get; set; } } public class B { public string Name { get; set; } //want to bind the DataTextField to this property } ASP.NET code behind DropDownList MyDropDownList = new DropDownList(); List<A> MyList = GetList()

DataTextField in a ListBox is a combination of 2 fields

允我心安 提交于 2019-12-08 02:55:51
问题 I have a listbox containing Users. The datasource is an generic list of the type User (contains, id, firstname, lastname, ...). Now I want to use the id as datavalue (through dataValueField) and I want LastName + ' ' + Firstname as a DataTextField. Can anyone tell me how this is possible? I'm using C# (ASP.NET). 回答1: The easiest way is to add a new property to the User class that contains the full name: public string FullName { get { return LastName + " " + FirstName; } } And bind the listbox

DataTextField in a ListBox is a combination of 2 fields

狂风中的少年 提交于 2019-12-06 10:44:05
I have a listbox containing Users. The datasource is an generic list of the type User (contains, id, firstname, lastname, ...). Now I want to use the id as datavalue (through dataValueField) and I want LastName + ' ' + Firstname as a DataTextField. Can anyone tell me how this is possible? I'm using C# (ASP.NET). The easiest way is to add a new property to the User class that contains the full name: public string FullName { get { return LastName + " " + FirstName; } } And bind the listbox to that. This has the advantage of centralising the logic behind how the full name is constructed, so you