0

我的 SqlDataSource 选择命令由 Eval 单向数据绑定语法的 String.Format 功能动态更改。它工作正常。但是,我需要将两列值放在中间,中间有一个空格(ItemType + '" "' + ItemDescription As ItemInfo),但是当我收到消息时我无法获得正确的语法:“服务器标签格式不正确"

你能帮我吗?非常感谢

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand='<%# Eval("TypeID", "SELECT ItemID, ItemType, ItemType + '" "' + ItemDescription As ItemInfo WHERE ItemType = {0}")%>'> </asp:SqlDataSource>

4

2 回答 2

0

HiI 以这种方式解决了这个问题(如How to use Single Quotes in Eval Format String 中所建议的)

在 items.aspx.vb 中

Protected Const SqlQuery As String = "SELECT ItemID, ItemType, ItemType + " + "' '" + " ItemDescription As ItemInfo WHERE ItemType = {0}"

在 items.aspx 中

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand='<%# Eval("TypeID", SQLQuery)%>'> </asp:SqlDataSource>

非常感谢

于 2010-04-08T16:37:19.083 回答
0

这可能是一个更普遍的问题

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ConnectionStrings:conn %>" 
         SelectCommand='<%# Eval(&quot;TypeID&quot;, &quot;SELECT ItemID, ItemType, ItemType + &quot;\" \"&quot; + ItemDescription As ItemInfo WHERE ItemType = {0}&quot;)%>'> 
 </asp:SqlDataSource>
于 2010-04-07T13:04:16.497 回答