Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i use
XML
<script language="javascript">
    function redirect() {
        window.location = "Product_Detail.aspx?idProduct=" + '<%# Eval("idProduct") %>';

    }
</script>

and

XML
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">


          <ItemTemplate>
              <li style="list-style:none" class="product_item">
                  <asp:Label ID="idProductLabel" runat="server" Text='<%# Eval("idProduct") %>' class="noneDisp" />
                 
                      <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("imageLink") %>' class="pic_product" onclick="redirect" />

                      <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' /><br />
                      <asp:Label ID="costLabel" runat="server" Text='<%# Eval("cost") %>' />                 

              </li>
          </ItemTemplate>


but it not work, how do i get idProduct of this item?
Posted

1 solution

Hi,
Try this:
HTML
OnClientClick='<%# String.Format("javascript:return redirect(\"{0}\")", Eval("idProduct").ToString()) %>'

And then change your JavaScript function to get a parameter(idProduct).
Your function:
XML
<script language="javascript">
    function redirect(idProduct) {
        window.location = "Product_Detail.aspx?idProduct=" + idProduct;
    }
</script>



Cheers
 
Share this answer
 
v2
Comments
summerrain_90 25-Apr-12 1:50am    
it still not work, i click this and nothing happened.
Reza Ahmadi 25-Apr-12 1:59am    
Then debug your function, try to watch what is being send in the 'redirect' function
Reza Ahmadi 25-Apr-12 2:05am    
One more thing, have you removed '<%# Eval("idProduct") %>' which was in your function as I moved them in the <asp:Image tag?
summerrain_90 25-Apr-12 2:08am    
thanks for your help! its work but i change OnClientClick = onclick.
=))
Reza Ahmadi 25-Apr-12 2:10am    
OK, Your welcome! But I don't know why OnClientClick does not work in your form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900