locked
Html toggle button in asp.net DataList RRS feed

  • Question

  • User454094798 posted

    Hi All,

    I am using Bootstrap toggle switch(which is html input checkbox) in Asp.Net DataList control. 

    I want to update changes of toggle switch to Database, how can i do that? Is it through Item Command or Select Command?

    Note: I don't want to use a button to update the changes of datalist.

    Tuesday, August 2, 2016 8:41 PM

Answers

  • User-271186128 posted

    Hi Tanu,

    I tried to store the status in hidden field, but how can i trigger itemCommand from this toggle switch?

    and how can i pass the CommandName and Command Argument to code behind.

    As far as I know, if using check box it will not trigger the ItemCommand event. I suggest you could add a button and set it invisible. Then, you could use the button control's CommandName and CommandArgument property. When, switch the checkbox, you could use JQuery to trigger the button click event.

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 4, 2016 11:37 AM

All replies

  • User-271186128 posted

    Hi Tanu,

    I am using Bootstrap toggle switch(which is html input checkbox) in Asp.Net DataList control. 

    I want to update changes of toggle switch to Database, how can i do that

    Since you are using html input tag, the code behind can't access the checkbox. I suggest you could use a Asp.net HiddenField control to store the checkbox state. When change the checkbox state, you could get the state value and set it to the HiddenField. Then, you could get the HiddenField value and update to the database.

    Here is a sample about using BootStrap Switch, you can check it: http://jsfiddle.net/sumw4/13/

    Is it through Item Command or Select Command?

    You could use the ItemCommand or UpdateCommand Event. More details, see:

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.updatecommand(v=vs.110).aspx

    Note: I don't want to use a button to update the changes of datalist.

    What do you mean about you don't want to use a button to update database?

    Best regards,
    Dillion

    Wednesday, August 3, 2016 3:09 AM
  • User454094798 posted

    Thanks for your response Zhi Lv.

    I tried to store the status in hidden field, but how can i trigger itemCommand from this toggle switch?

    and how can i pass the CommandName and Command Argument to code behind.

    Tanu

    Note: I don't want to use a button to update the changes of datalist.

    What do you mean about you don't want to use a button to update database?

    I am not using any button to update the status of toggle switch to DB.

    Hope its clear.

    Wednesday, August 3, 2016 9:53 PM
  • User-271186128 posted

    Hi Tanu,

    I tried to store the status in hidden field, but how can i trigger itemCommand from this toggle switch?

    and how can i pass the CommandName and Command Argument to code behind.

    As far as I know, if using check box it will not trigger the ItemCommand event. I suggest you could add a button and set it invisible. Then, you could use the button control's CommandName and CommandArgument property. When, switch the checkbox, you could use JQuery to trigger the button click event.

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 4, 2016 11:37 AM