0

Good Afternoon , I have collection of checkboxes under Listview .

Can u suggest me how to pass the count of checked and unchecked checkbox items . Label count has to be updated when checkbox is checked or unchecked .

My code

<ItemTemplate>
                    <li>
                        <p style="text-align: left; padding: 3px;">
                            <asp:Label ID="lblName" runat="server" Text='<%#Eval("Title")%>' CssClass="imglbl" /><br />
                            <img src="<%#Eval("ThumbNail")%>" style="vertical-align: middle;" height="120" width="110" id="myimg" title="Click to Play" /><br />
                            <asp:Label ID="lblpricetag" Text="Price($):" runat="server" Style="float: left; display: inline; margin-top: 8px;" /><asp:Label ID="lblPrice" runat="server" Text='<%#Eval("Price")%>' CssClass="imgprice" /><br />
                            <br />
                            <%--<input type="checkbox" id="chkaddtocart" value='<%#Eval("id")%>' name="chkaddtocart" onchange="chkonclick(this.checked,this.value);" />Add to Cart--%>
                            <asp:CheckBox ID="chkaddtocart" runat="server" Onclick=function() Text="Add to Cart" />
                        </p>
                    </li>
                </ItemTemplate>

I got it in script but i want it in codebehiend

this is my script code

 function chkonclick(o,chkvalue) {
        //alert(o + "," + chkvalue);
        if (o) {
            myitems += 1;
        }
        else {
            if (myitems > 0)
                myitems -= 1;
            else
                myitems = 0;
        }
        myitemslabel = myitems + " items";
        $("#txtitems").val(myitems.toString());
        $("#lblitems").html(myitemslabel);

    }
5
  • please add the your asp.net markup code for txtitems Commented Nov 22, 2013 at 10:13
  • I have this <input type="text" id="txtitems"/> in header section Commented Nov 22, 2013 at 10:19
  • So you want to update txtitems? if so your code should work. Label count has to be updated when checkbox is checked or unchecked what is this Label? Please edit your code with those markup Commented Nov 22, 2013 at 10:20
  • label count is txtitme am sorry for that Commented Nov 22, 2013 at 10:25
  • label count is txtitme am sorry for that .If 2 checkboxes checked count should be 2 .if 1 unchecked count should be 1 .This is what i need Bro Commented Nov 22, 2013 at 10:33

2 Answers 2

1

change your checkbox like this

 <asp:CheckBox ID="chkFocusArea" runat="server" OnCheckedChanged="chkFocusArea_CheckedChanged" AutoPostBack="true" />

You can make use of checkbox change event

protected void chkFocusArea_CheckedChanged(object sender, EventArgs e)  
{  
    CheckBox cb = (CheckBox)sender;  
   //update label count if checkbox is checked
}
Sign up to request clarification or add additional context in comments.

4 Comments

Can u suggest me the logic
@Kailas = you can check here : stackoverflow.com/questions/3068628/…
Am not passing Information to DB .I want to update a label with how many checkboes are checked and unchecked
@PranayRana saras answer chhu
0

You can provide a name for the checkbox as test var list=input[name=test] var count = 0; var total = 0; $(list).each(function() { if(this.checked) count++; total++; });

you can use these two variables for displaying what you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.