0

I am trying to make a div tag clickable . Following is the markup for it :

<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>

My C# code:

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

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

Now when I use onClick event of the div tag i get an error when i am using Eval() tag saying : The attribute name must be followed by an equal(=) sign and a value. If the value is in quotation marks, the quotation marks must match.

And is it the best way to navigate to a different page using location.href property?

The purpose I want that ID in the Eval tag is because i want to access that ID on the other page and display that particular product's details .

Abhishek Ghosh
  • 2,593
  • 3
  • 27
  • 60

1 Answers1

0

You're missing the context switch to server-code in this attribute

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

it should be

onclick="location.href='ProductDetails.aspx?ID=<%# Eval("VendorItemID") %>' "
Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • what is the difference between `<%# Eval() %>` and `<%: Eval() %>` ?? I guess it should be `<%# Eval() %>`... the latter gives error. – Abhishek Ghosh Mar 12 '15 at 12:56
  • @AbhishekGhosh http://stackoverflow.com/questions/957284/whats-the-deal (And you're right - ive updated the answer) – Jamiec Mar 12 '15 at 12:59
  • That was really helpful... In my case i did not want to use `Response.Write` hence `<%# %>` was useful to me .. Thanks anyways @Jamiec! – Abhishek Ghosh Mar 12 '15 at 13:02