2

I have a GridView and a linqdatasource. The GridView is editable and when the user clicks to edit a row I want to concatenate two of the fields in the linqdatasource and place it in a single textbox.

I tried something like:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Field1") %> - <%# Bind("Field2") %>'></asp:TextBox>

That didn't work.

2
  • What output did this actually produced? Commented Jan 20, 2011 at 4:13
  • The code displays only Field2. I'm not sure why. It doesn't error, but does not show the Field1 or the "-". Commented Jan 20, 2011 at 9:12

2 Answers 2

4

It wouldn't make sense to Bind two values in one textbox, though you can Eval two of them together like this

Text='<%# Eval("Field1","{0}") + "-" + Eval("Field2","{0}") %>'

The formatting parameter {0} isn't always needed.

Sign up to request clarification or add additional context in comments.

Comments

2

This will work:

Text='<%# Eval("Field1").ToString() + " " + Eval("Field2").ToString() %>'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.