博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
aspx页面
 1<asp:Label ID="LabelMessage" ForeColor="red" runat="server"></asp:Label>
 2
 3    <asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False" EmptyDataText="No Schedules"
 4        Width="100%">
 5        <Columns>
 6            <asp:TemplateField>
 7                <ItemTemplate>
 8                    <input name="Radio1" type="radio" value='<%# Eval("Id") %>' />
 9                </ItemTemplate>
10            </asp:TemplateField>
11            <asp:TemplateField>
12                <ItemTemplate>
13                    <input name="Checkbox1" type="checkbox" value='<%#Eval("Id") %>' />
14                </ItemTemplate>
15            </asp:TemplateField>
16        </Columns>
17    </asp:GridView>
18   
19    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="CheckSelected();" />

 1<script language="javascript">
 2    
 3        function  CheckSelected()
 4        {
 5            var inputsCheckPassenger = document.getElementsByName("CheckboxPassenger");
 6           var labelMessage = document.getElementById('<%=LabelMessage.ClientID%>'); 
 7           
 8           var inputsCheck = document.getElementsByName("Checkbox1");
 9
10            var isHasChecked = false;
11
12            for(var j = 0 ; j <   inputsCheck.length; j++)
13            {
14                if (inputsCheck[j].checked) 
15                {
16                     isHasChecked = true;
17                     break;
18                }
  
19            }

20
21            
22            if (isHasChecked == false)
23            {
24                //所有的checkbox都没有选中 
25                labelMessage.innerText = "Please select checkbox"
26                event.returnValue = false
27                return;  
28            }

29           
30           var inputsRadio = document.getElementsByName("Radio1"); 
31           var isHasCheckRadio = false;
32           
33           for (var k = 0; k < inputsRadio.length; k++)
34           {
35                if (inputsRadio[k].checked)
36               {
37                    isHasCheckRadio = true;
38                    break
39               }
 
40           }

41           
42           if (isHasCheckRadio == false)
43           {
44                //所有的radio都没有选中
45                labelMessage.innerText = "Please select RadionButuon"
46                event.returnValue = false
47                return;  
48           }

49        }

50
51    </script> 

cs取值代码
1string[] arrayId = Request.Form["Checkbox1"].Split(',');//返回选中的checkbox的数组
2string SelectedId = Request.Form["Radio1"];//返回选中的radiobutton的value值