首页 > 解决方案 > 在 C# 中绑定 2 个字段

问题描述

我正在尝试在 aspx 页面中绑定 2 个字段

使用这个脚本

<asp:Label runat="server" ID="lblListText" Text=<%# Eval("CodeType") %> : <%# Eval("Code") %> > </asp:Label>

但是你我收到了这个错误

Compiler Error Message: CS1525: Invalid expression term '>'

我试过

<asp:Label runat="server" ID="lblListText" Text=<%# Eval("CodeType")  : # Eval("Code") %> > </asp:Label>

收到

Compiler Error Message: CS1040: Preprocessor directives must appear as the first non-whitespace character on a line

试过了

<asp:Label runat="server" ID="lblListText" Text=<%# Eval("CodeType")  :  Eval("Code") %> > </asp:Label>

拿到

Compiler Error Message: CS1003: Syntax error, ',' expected

不知道如何获得 CodeType 然后是冒号然后是 Code?

标签: c#asp.net

解决方案


我找到了答案

<asp:Label runat="server" ID="lblListText" Text='<%#Eval("CodeType").ToString() +" : "+ Eval("Code").ToString() %>' > </asp:Label>

推荐阅读