【问题标题】:Parser Error Message解析器错误消息
【发布时间】:2014-10-19 12:09:51
【问题描述】:

我的 asp.net 代码


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tdfConnectionString2 %>" SelectCommand="select * from answer,users where question_id="<%=Session["qid"]%>" and answer.user_id=users.user_id"></asp:SqlDataSource>
    <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource1">
        <HeaderTemplate>
            <div class="container">
        </HeaderTemplate>
        <ItemTemplate>
           <div class="panel panel-primary">
               <div  class="panel-heading">

                   <h2 class="panel-title"><a href="Answer.aspx?qid=<%#Eval("question_id") %>"><asp:Label ID="Label2" runat="server" Text="Reply"></asp:Label></a></h2>
              </div><!--panel-heading-->
               <div class="panel-body">
                       <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("uimg")%>' Height="100" Width="100" />
                   <asp:Label ID="Label1" runat="server" Text='<%#Eval("answer_detail") %>'></asp:Label>
                   <br />
                   <asp:Label ID="Label4" runat="server" Text='<%#Eval("username") %>'></asp:Label>
                   <br />
            </div><!--panel-heading-->
        </ItemTemplate>
    </asp:Repeater>

什么时候浏览应用程序

“/”应用程序中的服务器错误。

解析器错误

描述:解析服务此请求所需的资源时出错。请查看以下特定的解析错误详细信息并适当地修改您的源文件。

解析器错误消息:服务器标签格式不正确。

来源错误:

第 28 行:第 29 行:
第 30 行:
" SelectCommand="select * from answer,users where question_id="" 和 answer.user_id=users.user_id"> 第 31 行:
第 32 行:

源文件:/Admin/QuestionView.aspx 行:30

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.34212

【问题讨论】:

  • 你重复了",试试...question_id='

标签: asp.net sql-server c#-4.0


【解决方案1】:

您不能使用&lt;%= ... %&gt; 设置服务器端控件的属性。内联表达式&lt;% %&gt;只能用于aspx页面或用户控件的顶级文档级别,不能嵌入到服务器控件的标签属性中(如&lt;asp:SqlDataSource... SelectCommand =&lt;%= %&gt; ..&gt;)。

您不能在带有runat=server 的控件内使用&lt;%=Session["qid"]%&gt;。这不会被评估,因为这是一个服务器控制。您可以在后面的代码或 page_load 事件中设置该值。

您需要在 page_load 事件中添加以下内容。

SqlDataSource1.SelectCommand = select * from answer,users where question_id=" + Session["qid"].ToString() + " and answer.user_id=users.user_id"

SqlDataSource1.ConnectionString = "&lt;PUT_YOUR_Connectrin_String_Here&gt;";

在 aspx 中更新 SqlDataSource1 如下。

&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server"&gt;&lt;/asp:SqlDataSource&gt;

已经在这里解释了 - Web Forms error message: "This is not scriptlet. Will be output as plain text"

【讨论】:

  • 同样的问题一次又一次出现..! :(
  • @sarfarazchohan,你还需要在后面的代码中设置ConnectionString 属性!,然后从这里删除。同样在从 aspx 删除后面的代码中设置之后。
  • 谢谢兄弟...!解决了..!再次感谢它非常有帮助..! :)
猜你喜欢
  • 2011-10-24
  • 2011-03-03
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-18
  • 1970-01-01
相关资源
最近更新 更多