【发布时间】:2015-05-24 23:02:00
【问题描述】:
我在将数据绑定到数据列表时遇到此错误 字符文字 asp.net 中的字符太多
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="android.aspx.cs" Inherits="finalproject.android" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.style1
{
width:900px;
}
.style2
{
width:633px;
text-align:left;
}
.style4
{
width:185px;
text-align:center;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DataList ID="DataList1" runat="server" DataKeyField="modelid"
style="text-align: center; color: #333333;" RepeatColumns="3"
Width="283px" DataSourceID="SqlDataSource2" CellPadding="3"
BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellSpacing="1" >
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
<ItemTemplate>
<br />
<div align="left"></div>
<table cellspacing="1" class="style4" style="border:1px ridge #9900FF">
<tr>
<td style="border-bottom-style:ridge; border-width: 1px; border-color: #000000">
<asp:Label ID="Label1" runat="server" Text="<%# Eval('brand') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Height="252px"
ImageUrl="<%# Image %>" style="margin-left: 0px" />
</td>
</tr>
<tr>
<td>
ModelID<asp:Label ID="Label2" runat="server" Text="<%# Eval('modelid') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
CommandArgument="<%# Bind('ModelID') %>" Text="Add to Cart" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" />
</td>
</tr>
</table>
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:VISHConnectionString2 %>"
SelectCommand="SELECT [Image], [modelid], [brand] FROM [adddetails]">
</asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table align="left" class="style2">
<tr>
<td>
<asp:Label ID="Label3" runat="server" style="color: #333333"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
我在将数据绑定到数据列表时遇到此错误 字符文字 asp.net 中的字符太多
【问题讨论】:
-
在整个页面中从
Text="<%# Eval('modelid') %>"更改为Text='<%# Eval("modelid") %>'。在 Text= 之后您需要使用单引号,而在 Eval 中绑定时使用双引号。 -
是的,我明白了,谢谢你