0
我在做一个电影评论网站。 ShowMovie.aspxα-ID =在.aspx中获取ID
我上无法从URL获得标识在.aspx页面中
<table border="1" cellpadding="1" cellspacing="1" style="width: 500px;">
<tbody>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblType" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID='SqlDataSource1' runat='server' ConnectionString='<%$ ConnectionStrings:con %>'
SelectCommand='SELECT [Comment] FROM [Comment] where [MovieId]=<%= Request.QueryString("Id") %>'>
</asp:SqlDataSource>
</tbody>
</table>
,但我可以在.aspx.cs页面获取标识
protected void Page_Load(object sender, EventArgs e) {
Id = Request.QueryString["Id"];
String types = "";
con = new Connect().Connection();
cmd = new SqlCommand("Select * from Movie where Id=" + Id, con);
dr = cmd.ExecuteReader();
dr.Read();
lblTitle.Text = dr["Title"].ToString();
lblDescription.Text = dr["Description"].ToString();
Picture.ImageUrl = dr["Picture"].ToString();
dr.Close();
}
这是错误 “<”附近的语法不正确。 异常详细信息:System.Data.SqlClient.SqlException:“<”附近的语法错误。
堆栈跟踪: [SQLEXCEPTION(0x80131904):附近有语法错误<“。]
在那里你定义的ID? – Adil
你有试过吗? (硬括号) <%= Server.HTMLEncode(的Request.QueryString [ “ID”])%> 参考: http://stackoverflow.com/questions/9725385/getting-a- url-parameter-into-asp-net-label –
它位于ShowMovie.aspx页面。 Id来自Default.aspx "> –
tayfun