Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Change your double quotes in the onchange to single quotes.

share|improve this answer
    
Actually I thought I had tried that, but it does remove the compiler error. But the resulting client code seems wrong. I get the javascript function attached to a <span> with the checkbox inside, and the <%# Eval("Price") %> hasn't been evaluated. How should I formulate my checkbox properties? –  Chau Sep 24 '09 at 9:33
1  
Here's one way, bit hacky, but hey... michaelteper.com/archive/2009/03/03/… –  Paddy Sep 24 '09 at 10:31
    
Hi Paddy, I will try the solution in your link. Thanks for your efforts :) –  Chau Sep 24 '09 at 11:01
<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>
share|improve this answer
    
What does this mean? –  Chau Oct 20 '09 at 6:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.