JS判断CheckBox 的选中值

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <asp:GridView ID="gvSelectPayType" Width="100%" runat="server" AutoGenerateColumns="False"
                                    Style="margin-left: 0px" DataKeyNames="function_id,pay_id">
                                    <Columns>
                                        <asp:BoundField DataField="function_name" HeaderText="功能服务" />
                                        <asp:BoundField DataField="pay_type_name" HeaderText="选择计费方式" />                                       
                                        <asp:TemplateField HeaderText="购买量" Visible="true">
                                            <ItemTemplate>
                                                购买量<asp:TextBox ID="txtAmount" runat="server" AutoPostBack="True" Height="20px"
                                                    MaxLength="4" onclick="this.focus()" onkeydown="KeyIsNumber()" OnTextChanged="txtAmount_TextChanged"
                                                    ToolTip="购买量必须填写" Width="50px">0</asp:TextBox>
                                                <asp:Label ID="lblUnit" runat="server" Text=""></asp:Label>
                                                <font color="red">*</font>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                              
                                       
                                        <asp:TemplateField HeaderText="购买量" Visible="False">
                                            <ItemTemplate>
                                                <asp:Label ID="lblAmount" runat="server" Text="lblAmount"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="outlay"  DataFormatString="{0:N2}" HeaderText="单价(元)"/>
                                        <asp:TemplateField HeaderText="费用(元)">
                                            <ItemTemplate>
                                                &nbsp;<asp:Label ID="lblMoney" runat="server"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="合计(元)" Visible="False">
                                            <ItemTemplate>
                                                <asp:Label ID="lblTotalMoney" runat="server"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </ContentTemplate>
                        </asp:UpdatePanel>

 

 

 

 

 <script language="javascript" type="text/javascript">
 
    function Check(id){
        var conId=id.value;
        var array=new Array();
        array=conId.split(',');
        var conName=array[0];
     for(i = 0;i < document.forms["aspnetForm"].length; i++)
        { 
          var name=document.forms["aspnetForm"][i].value;
          var arrayId=new Array();
          arrayId=name.split(',');
          var temp="";
          if(arrayId.length==2){
            temp=arrayId[0];
            if(temp==conName&&name!=conId){
                 document.forms["aspnetForm"][i].checked=false;
            }
           
          }
                                                                 
        }
    }

</script>  
   

 

//加载时绑定值

 for (int i = 0; i < list.Count; i++)
        {
            HtmlInputCheckBox chk = (HtmlInputCheckBox)gvServices.Rows[i].FindControl("chk");
            chk.Value = list[i].function_name + "," + list[i].Pay_id;
        }

 

//保存按钮事件

try
        {
            DataSet ds = new DataSet();
            DataTable tb = new DataTable();
           
            tb.Columns.Add("function_id");
            tb.Columns.Add("pay_id");          
            foreach (GridViewRow gvr in gvServices.Rows)
            {
                HtmlInputCheckBox rb = (HtmlInputCheckBox)gvr.Cells[1].FindControl("chk");
           
                if (rb.Checked)
                {
                    DataRow dr = tb.NewRow();
                    dr["function_id"] = gvServices.DataKeys[gvr.RowIndex].Values[0];
                    dr["pay_id"] = gvServices.DataKeys[gvr.RowIndex].Values[1];
                    tb.Rows.Add(dr);                   
                }
            }
            ds.Tables.Add(tb);
            if (tb.Rows.Count > 0)
            {
                mvApplyService.ActiveViewIndex = 1;
                gvSelectPayType.DataSource = ServiceProxy.GetServicesDetailsBy(ds);
                gvSelectPayType.DataBind();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "<script language='javascript'>alert('请选择要购买的服务!')</script>");
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(),"alert", "<script language='javascript'>alert('" + ex.Message.ToString()+ "')</script>");
        }

你可能感兴趣的:(checkbox)