使用Div标签的location.href属性时,Eval不起作用

时间:2015-03-12 12:48:48

标签: javascript c# html

我正在尝试点击div标记。以下是它的标记:

<asp:Repeater ID="rptr" runat="server">
            <ItemTemplate>
                <div class="col-lg-4 col-md-4 col-sm-4 mb">
                            <div class="content-panel pn">
                                <div id="profile-01" style='<%# "background-image : url("+Eval("Photo").ToString()+") " %>'></div>
                                <div class="profile-01 centered" onclick="location.href='ProductDetails.aspx?ID=Eval("VendorItemID")' ">
                                    <p><%# Eval("Name") %></p>
                                </div>
                                <div class="centered">
                                    <h5><i class="fa fa-gift"></i><br/><%# Eval("Description") %></h5>
                                </div>
                            </div><! --/content-panel -->
                        </div><! --/col-md-4 -->
            </ItemTemplate>
        </asp:Repeater>

我的C#代码:

if (!IsPostBack)
            {
                VendorItemLogic vendorItem = new VendorItemLogic();
                DataTable dt = vendorItem.populateProducts(Convert.ToInt32(Request.QueryString["ID"]));

                rptr.DataSource = dt;
                rptr.DataBind();
            }

现在,当我使用onClick标记的div事件时,当我使用Eval()标记时,我会收到错误:属性名称必须后跟等号( =)符号和值。如果该值使用引号,则引号必须匹配。

这是使用location.href属性导航到其他页面的最佳方式吗?

我想在Eval代码中使用该ID的目的是因为我想在另一页上访问该ID并显示该特定产品的详细信息。

1 个答案:

答案 0 :(得分:0)

您在此属性中缺少上下文切换到服务器代码

onclick="location.href='ProductDetails.aspx?ID=Eval("VendorItemID")' "

应该是

onclick="location.href='ProductDetails.aspx?ID=<%# Eval("VendorItemID") %>' "