开发者

ASP.NET dynamically created check boxes won’t clear after post back

I have a list of check box’s displaying depending on what a used selects from a drop down box. When the value of the drop down box is changed post back occurs. Also when a check box is changed post back occurs.

My problem is if I select a value from the drop down box and say 6 check boxes are created. I decide that I want to uncheck box number 3. Then change my mind and select a new value from the drop down list. When the new check boxes are created check box 3 will remain unchecked!?!

I really haven’t been able to find a solution to this problem any help or advise would be greatly appreciated. I should also mention that both the check boxes and dropdown operate inside an update Panel.

Here is the code that generates the check boxes:

For Each _element In myTools.getElements(templateID, myTools.getConnectionStringFromAirlineName(ddl_Source.SelectedValue)).Rows
Dim tr As New HtmlTableRow
Dim td_elementChecked As New HtmlTableCell
Dim cb_ID As New CheckBox
cb_ID.ID = templateID & _element.item(0)
// As you can see i'm setting check to true each time?
cb_ID.Checked = True
cb_ID.AutoPostBack = True
cb_ID.DataBind()
AddHandler cb_ID.CheckedChanged, AddressOf handlesGe开发者_如何学编程nericCheckedChange
Dim td_elementName As New HtmlTableCell
Dim lbl_elementName As New Label

td_elementName.Controls.Add(lbl_elementName)
td_elementChecked.Controls.Add(cb_ID)
tr.Cells.Add(td_elementChecked)
tr.Cells.Add(td_elementName)
table_elements.Rows.Add(tr)
table_elements.DataBind()
present = True
Next

The id of the checkbox bears meaning and can’t be changed, I have a feeling this might have something to do with it. The ID is used to indicate what needs to be processed.


Before you reload the controls is it possible for you to create a new panel.. in this way you are starting afresh. this is just a suggestion.


You will need to supply more code but it sounds like you are redrawing all the checkboxes when you change the dropdowns selected value. If that is the case then the newly created checkboxes will not retain the "check" you had previously assigned. What you might need to do is when you postback the data is record the current state of the form. Record what values are selected so that when you have to redraw the form you can apply these changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜