Ideas:
1. Use Javascript to obtain the CheckListBox ID in FormView.
-The key point is <% = FormView1.FindControl ("CheckBoxList1"). ClientID %>. Because CheckListBox exists in the FormView control, it must be written in the preceding method.
-Generally, you only need to enter the Control ID, for example, document. getElementById ('checkboxlist1'). childNodes [0];
-Sometimes the Control ID is inconsistent with the ClientID, so it is best to use document. getElementById ('<% = CheckBoxList1.ClientID %>'). childNodes [0];
2. verify whether the sever has been selected by using reverse sript;
Note:
1. CheckListBox because there is a branch option, there are several checkboxes in one row, which is not selected by default. The following code is used: <script language = "JavaScript">
<! --
Function readListControl ()
{
Var tableBody = document. getElementById ('<% = FormView1.FindControl ("CheckBoxList1"). ClientID %>'). childNodes [0];
For (var I = 0; I <tableBody. childNodes. length; I ++)
{
Var currentTd = tableBody. childNodes [I]. childNodes [0];
Var listControl = currentTd. childNodes [0];
If (listControl. checked = true)
Alert ('#' + I + ': is checked ');
}
}
// -->
</Script>
2. if a row needs to contain multiple checklistboxes at the same time, the Code must be rewritten. Considering that there may be a total of 11 checkboxes, there will be four in one row and the last one in the last row will not, however, the code will still be monitored, so you need to confirm whether it is empty, otherwise there will be errors. The Code is as follows: <script language = 'javascript '>
<! --
Function MultiValidator ()
{
Var tableBody = document. getElementById ('<% = FormView1.FindControl ("CheckBoxList1"). ClientID %>'). childNodes [0];
For (var I = 0; I <tableBody. childNodes. length; I ++)
{
For (var j = 0; j <tableBody. childNodes [I]. childNodes. length; j ++)
{
Var currentTd = tableBody. childNodes [I]. childNodes [j];
Var listControl = currentTd. childNodes [0];
If (listControl! = Null)
{
If (listControl. checked = true)
{
Alert ('#' + I + ',' + j + ': is checked ');
}
}
}
}
Return false;
}
// -->
</Script>