Question

In an ASP:ListView control, I have a checkbox for each row. Each row represents a product with a corresponding price. I want the customer to select one or more products and calculate a total price client side.

So far, I've used the following code, but it does not work:

<asp:CheckBox ID="CheckBox" 
              runat="server" 
              Text="" 
              Checked='<%# Convert.ToBoolean(Eval("Selected")) %>'
              onchange="changeTotal(this, <%# Eval("Price")) %>)"
/>

I have a javascript function changeTotal(referer, value) which should determine if the product was just selected and add/subtract the product price from a total.

The PROBLEM is the javascript function assignment in the CheckBox definition - what is wrong with this approach? Why can't I assign a static price for the javascript function? When I remove the <%# Eval("Price")) %> part from the checkbox, the code compiles without errors.

Was it helpful?

Solution

Change your double quotes in the onchange to single quotes.

OTHER TIPS

<script language="javascript" type="text/javascript">
 function validatecheckbox(mode)
 {
 //alert('mode' + mode);
 //mode : 1  From : chkdeRegister
 //mode : 2  From : chkcancel
  var chkdeRegister = document.getElementById ("<%=chkdeRegister.ClientID%>"); 
  var chkcancel = document.getElementById("<%=chkcancel.ClientID%>");

  //alert('chkdeRegister: ' + chkdeRegister.checked);
  //alert('chkcancel: ' + chkcancel.checked);
  if(mode==1)
  {
    if(chkdeRegister.checked)
     {
      chkcancel.checked=false;
     }
  }
  else
  {
   if(chkcancel.checked)
     {
      chkdeRegister.checked=false;
     }
  }
 }
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top