Concatenating Two Properties for Display in a DropDownList

后端 未结 3 1219
鱼传尺愫
鱼传尺愫 2021-01-21 00:30

Background

In our last adventure, I was attempting to properly show a Dictionary>. Thanks to the helpful answers in that post, I r

相关标签:
3条回答
  • 2021-01-21 00:50

    Maybe I'm missing something (didn't look at the earlier question), but why wouldn't you just do this?

    <%# Eval("Name") + Eval("Type") %>
    
    0 讨论(0)
  • 2021-01-21 00:54

    I had to convert the object to a string before concatenating the string. This worked for me.

    Text='<%# Eval("LastName").ToString() + ', ' + Eval("FirstName").ToString() %>'

    0 讨论(0)
  • 2021-01-21 01:07

    As it turns out, the problem is easily solvable if the two columns from the table are concatenated and into one column, like so:

    SELECT Column1Name + ' - ' + Column2Name AS Column3Name FROM Table1 WHERE...

    This turns this:

    Column1Name          Column2Name
    -----------          ----------- 
    Stuff1               Stuff5
    Stuff2               Stuff6
    Stuff3               Stuff7
    Stuff4               Stuff8
    

    Into this:

    Column3Name
    ---------------
    Stuff1 - Stuff5
    Stuff2 - Stuff6
    Stuff3 - Stuff7
    Stuff4 - Stuff8
    

    When all else fails, think a little lower level.

    0 讨论(0)
提交回复
热议问题