locked
How can i bind the display of my database to the checkbox. In order to only show the data table when clicked? RRS feed

  • Question

  • User-456405099 posted

    I am using Visual Studios 2017 and I have a checkbox and when click it I want it to be able to display the data from a database. How can I connect the two using asp.net c#. Is there a template or something I can use?

    Wednesday, June 12, 2019 8:25 PM

All replies

  • User-2054057000 posted

    You will have to implement the jQuery Change Method to do this stuff. I have shown (in the below code) how to achieve this:

    <input type="checkbox" id="mycheckbox" /> My Checkbox
    
    $("#mycheckbox").change(function () {
        if ($(this).is(":checked")) {
            // make ajax call to get the database values
        }
    });

    Refer: Check Uncheck all checkbox Of ASP.NET Checkboxlist using jQuery

    Thursday, June 13, 2019 8:01 AM
  • User61956409 posted

    Hi Elapache1032,

    Welcome to ASP.NET forums.

    Elapache1032

    I have a checkbox and when click it I want it to be able to display the data from a database. How can I connect the two using asp.net c#. Is there a template or something I can use?

    If you'd like to dynamically show/hide records based on the status of asp:CheckBox, yogyogi has shared an approach to achieve it on client side, if you want to achieve the requirement on client side using jQuery, please refer to it.

    Besides, you can also achieve it from code behind, like below.

    On web page, set AutoPostBack="true" for your asp:CheckBox control.

     <asp:CheckBox ID="chk_show" runat="server" OnCheckedChanged="chk_show_CheckedChanged" AutoPostBack="true" />

    On OnCheckedChanged event, you can dynamically set Visible property to show/hide the data control, like below. 

    protected void chk_show_CheckedChanged(object sender, EventArgs e)
    {
        //your code logic here
    
        if (this.chk_show.Checked)
        {
            GridView1.Visible = true;
        }
        else
        {
            GridView1.Visible = false;
        }
    }

    With Regards,

    Fei Han

    Thursday, June 13, 2019 9:01 AM