Click here to Skip to main content
14,920,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to fire click event on checkboxlist..
after clicking checkbox bind data from database and dispalyed in to list view using mvc

this functionality used for my project filtaration for venues like by cost,capacity,venuetypes like that ...

please help me..friends

i am strucking from more than 1 week
for this functionality

What I have tried:

How to fire click event on checkboxlist..
after clicking checkbox bind data from database and dispalyed in to list view using mvc

view...

HTML
<div class="panel">
                        <h2>No of Guests</h2>
                        <div class="panelcontent">
                            <ul style="margin-left: 21px;margin-top:7px;">
                                @foreach (var item in Model.Bind_No_of_Guests)
                                {
                                    <li>
                                        <a href="#">
                                            <input type="checkbox" name="monitor" @*onclick="toggle(this, 'myGroup')"*@ />
                                            <span><b>@item.NoOfGuestsBinding </b> </span>
                                        </a>
                                    </li>
                                }
                            </ul>
                        </div>
                    </div>



Controler...

C#
public ActionResult List(Home obj,int page=1,int pagesize=3)
        {
            Menubar(obj);
            
            obj.Bind_No_of_Guests = obj.BindNoOfGuests();
            
            return View(obj);
        }



Model...

C#
public List<Home> BindNoOfGuests()
{
    List<Home> NoOfGuests = null;
    MySqlCommand cmd = new MySqlCommand("select No_of_Guests  from Bind_No_of_Guests", con);
    con.Open();
    MySqlDataReader rdr = cmd.ExecuteReader();
    NoOfGuests = new List<Home>();
    while (rdr.Read())
    {
        var Guests = new Home();
        Guests.NoOfGuestsBinding = rdr["No_of_Guests"].ToString();
        NoOfGuests.Add(Guests);
    }
    con.Close();
    return NoOfGuests;
}



javascript..

<script>



$(document).ready(function () {
$("#checkBoxId").click(function () {

var getchkid = $(this).attr('id');
var isChecked = $('#' + getchkid).is(':checked');

if ($('#' + getchkid).is(':checked') == true) {
$('#td' + $(this).val()).css("color", "white");
$('#td' + $(this).val()).css("background-color", "blue");
}
else {
$('#td' + $(this).val()).css("color", "black");
$('#td' + $(this).val()).css("background-color", "white");
}
});
});
</script>
Posted
Updated 9-Aug-16 0:09am
v2
Comments
njammy 9-Aug-16 5:13am
   
Please can you post your JavaScript code as well.
By the way, is your issue that the click event you declared is not firing?
Or that the controller action is not being called on click?
Member 11652153 9-Aug-16 6:09am
   
<script>



$(document).ready(function () {
$("#checkBoxId").click(function () {

var getchkid = $(this).attr('id');
var isChecked = $('#' + getchkid).is(':checked');

if ($('#' + getchkid).is(':checked') == true) {
$('#td' + $(this).val()).css("color", "white");
$('#td' + $(this).val()).css("background-color", "blue");
}
else {
$('#td' + $(this).val()).css("color", "black");
$('#td' + $(this).val()).css("background-color", "white");
}
});
});
</script>

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