Which CheckBox was clicked in a CheckBoxList
-
This is the 3rd time I am posting on this, because did not get my answer before. I am using a CheckBoxList for convenience, as I have several options. But I notice the CheckBoxList itself is the sender when a checkbox is clicked. So, how do I know which one was clicked? In older days, CheckBoxes would be put in a group and in the CheckedChanged event handler, we could use the sender to know which one was clicked. But sorry, I haven't found any property or method for the CheckBoxList control that will provide me with this info thats the first thing to know when using CheckBoxes. Thanks.
-
This is the 3rd time I am posting on this, because did not get my answer before. I am using a CheckBoxList for convenience, as I have several options. But I notice the CheckBoxList itself is the sender when a checkbox is clicked. So, how do I know which one was clicked? In older days, CheckBoxes would be put in a group and in the CheckedChanged event handler, we could use the sender to know which one was clicked. But sorry, I haven't found any property or method for the CheckBoxList control that will provide me with this info thats the first thing to know when using CheckBoxes. Thanks.
Use the SelectedIndexChanged event, I am pretty sure that the sender on that event is the CheckBox that you want.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
-
This is the 3rd time I am posting on this, because did not get my answer before. I am using a CheckBoxList for convenience, as I have several options. But I notice the CheckBoxList itself is the sender when a checkbox is clicked. So, how do I know which one was clicked? In older days, CheckBoxes would be put in a group and in the CheckedChanged event handler, we could use the sender to know which one was clicked. But sorry, I haven't found any property or method for the CheckBoxList control that will provide me with this info thats the first thing to know when using CheckBoxes. Thanks.
You were given the only possible answer. You can know which items are selected, but you'll need to maintain a list of previously selected items, to work out which item was changed.
Ekjon wrote:
In older days, CheckBoxes would be put in a group and in the CheckedChanged event handler, we could use the sender to know which one was clicked.
This still works if you're using forms. There was no such event in ASP.NET, ever.
Christian Graus Driven to the arms of OSX by Vista.
-
Use the SelectedIndexChanged event, I am pretty sure that the sender on that event is the CheckBox that you want.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
-
You were given the only possible answer. You can know which items are selected, but you'll need to maintain a list of previously selected items, to work out which item was changed.
Ekjon wrote:
In older days, CheckBoxes would be put in a group and in the CheckedChanged event handler, we could use the sender to know which one was clicked.
This still works if you're using forms. There was no such event in ASP.NET, ever.
Christian Graus Driven to the arms of OSX by Vista.
Hello Christian, If the CheckBoxList is databound, in the page load, I get the information from the table and bound it with the CheckBoxList - If(!Page.IsPostBack){...}. Therefore, some boxes appear as selected based on the table data. Now, when a selected box is clicked - I need to do 2 things - i) know which one was clicked and based on that, ii) delete info from the table and refresh the display based on new info. The problem - since the CheckBoxList is databound, when a selected one is clicked - if I don't delete that record from the table, the de-selection doesn't work. Even if I maintain a list of selected ones, now with a click if I don't know which one was clicked - I cannot delete it from the table. So maintaining a list here is not helping. But I am sure you can indicate the right direction. Thanks. Ekjon
-
Hello Christian, If the CheckBoxList is databound, in the page load, I get the information from the table and bound it with the CheckBoxList - If(!Page.IsPostBack){...}. Therefore, some boxes appear as selected based on the table data. Now, when a selected box is clicked - I need to do 2 things - i) know which one was clicked and based on that, ii) delete info from the table and refresh the display based on new info. The problem - since the CheckBoxList is databound, when a selected one is clicked - if I don't delete that record from the table, the de-selection doesn't work. Even if I maintain a list of selected ones, now with a click if I don't know which one was clicked - I cannot delete it from the table. So maintaining a list here is not helping. But I am sure you can indicate the right direction. Thanks. Ekjon
You have a list, and items that are checked, the user clicks on an item to select which one to delete ? Sounds like you need to rethink your UI.
Christian Graus Driven to the arms of OSX by Vista.
-
You have a list, and items that are checked, the user clicks on an item to select which one to delete ? Sounds like you need to rethink your UI.
Christian Graus Driven to the arms of OSX by Vista.
Yes, like the list displays notification options. The user selects them to be notified when an event occurs. Then later on, user can change mind and de-select one - indicating he/she doesn't want to be notified in that event. Thats why I need to delete it from the table. Thanks.