1

I have a list box in my aspx page:

<asp:ListBox ID="lstTreatmentProvider" runat="server" SelectionMode="Multiple" Width="175px"
                                        Height="81" CssClass="SingleColumnlist" DataSourceID="dtsTreatmentProviders" DataTextField="FirstName" DataValueField="ServiceId"></asp:ListBox>

I am using this datasource for listbox:

<asp:ObjectDataSource ID="dtsTreatmentProviders" runat="server" SelectMethod="GetAllTreatmentProviders"
                        TypeName="Pc.PrecisionCare2.BLL.Administration.TreatmentProvider.TreatmentProviderBO"
                        SortParameterName="sortExpression"></asp:ObjectDataSource>

As you can see, I am using in list box, DataTextField="FirstName" because my datasource returns some data of treatment provider including first name, last name etc.

I want to have my list box as containing First Name + Last Name Can I do this somehow using DataTextField property?

PS: I do not want to do this in cs file. I want something in aspx.

Thanks in advance.

asma
  • 2,795
  • 13
  • 60
  • 87

4 Answers4

0

You can get the First Name + Last Name in your SQL query, if you don't want to do it in code behind. e.g...

Select ([First Name] + [Last Name]) as [First Name],... from TableName
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • Im using LINQ Query and that is used at many other places so I don't want to change that. – asma Jun 06 '11 at 06:18
  • I mentioned already that I don't want to do in cs file. But I think I have only these two options :( – asma Jun 06 '11 at 06:27
0

You can try adding a Public property to your TreatmentProviderBO like below

public String FullName
{
    get { return FirstName + " " + LastName ;}
}

You can set the DataTextField to FullName.

If you can't edit the BO, I think you can use Extension Methods, though I'm not very sure whether you can give a method name to DataTextField. You may try.

The King
  • 4,600
  • 3
  • 39
  • 58
0

Would this post be helpful for you?

Bind drop down list with Dictionary

I think you could use the anonymous type too.

Community
  • 1
  • 1
ChristiaanV
  • 5,401
  • 3
  • 32
  • 42
0

If you don't want to change the query as you are sticking with LINQ try the following one

  var aa = (from Varible in Collection select new { name = Varible.FirstName + Varible.LastName }).ToList();

Now set the DataTextField Property to "name". Hope it helps.

Maxymus
  • 1,460
  • 2
  • 14
  • 22