0

Say I have a textbox that I want to display the FirstName from a database I would go:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("FirstName") %>'></asp:TextBox>

However I want to display both the First and LastName in this textbox.

Is it possible to do this using Eval using the one textbox?

Coder 2
  • 4,761
  • 12
  • 40
  • 43

2 Answers2

4

You can do:

<%# Eval("FirstName") + " " + Eval("LastName") %>

or

<%# String.Format("{0} {1}", Eval("FirstName"), Eval("LastName")) %>
Victor
  • 4,721
  • 1
  • 26
  • 31
1

One approach is to have a separate property called FullName that looks like this:

public string FullName
{
  get { return FirstName + " " + LastName }
}

Then you can reference this property instead of FirstName.

Alternatively, you can use String.Format to combine both properties inside a single Eval as described here.

Community
  • 1
  • 1
newdayrising
  • 3,762
  • 4
  • 27
  • 31