GridView JavaScript HtmlInputChecBox

来源:互联网 发布:sql select as where 编辑:程序博客网 时间:2024/05/30 23:16
 JavaScript:
    <script language="javascript">
   var SelectCount=0;
    function slcNo_click(sender,selectCount)
{
//alert(selectCount);
SelectCount=selectCount;
var count=0;
var   chkother=   document.getElementsByTagName("input");
for(i=0;i<chkother.length;i++)
{
  if(   chkother[i].type=='checkbox') 
  {
 if(chkother[i].checked)
 {
   count++;
 }
 if(count>selectCount)
{
sender.checked=false;
alert("选择数不能大于3");

}

}
}

}
function Check()
{

//alert(SelectCount);
//return false;
var count=0;
  var   chkother=   document.getElementsByTagName("input");
 for(i=0;i<chkother.length;i++)
{
  if(   chkother[i].type=='checkbox') 
  {
     if(chkother[i].checked)
 {
   count++;
 }
  }
}
  if(count<SelectCount)
  {
  alert("入围数不够!");
  return false;
  }
  else if(count==SelectCount)
  {
  return true;
  }
}
    </script>


.aspx:

        <asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="False" CellPadding="2" ForeColor="#333333" GridLines="None" Width="100%" OnRowDataBound="GridView2_RowDataBound" CellSpacing="1" AllowPaging="True" PageSize="15" OnPreRender="GridView2_PreRender">
        <Columns>
            <asp:TemplateField HeaderText="投票">
                <ItemTemplate>
   
                    <input id="checkboxname" runat="server" name="checkboxname" type="checkbox" />
                    <asp:HiddenField ID="hidden_id" runat="server" Value='<%#Eval("BallotedMedicineID") %>' />
                   
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
            </asp:TemplateField>
        <asp:BoundField DataField="MedicineName" HeaderText="药品名" >
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:BoundField>
          <asp:BoundField DataField="CurrencyName" HeaderText="通用名" >
              <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
          </asp:BoundField>
          <asp:BoundField DataField="DrugFormName" HeaderText="剂型" >
              <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:BoundField>
          <asp:BoundField DataField="StandardName" HeaderText="规格" >
              <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:BoundField>
          <asp:BoundField DataField="QualityLevelName" HeaderText="质量层次" >
              <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:BoundField>
 
           <asp:TemplateField HeaderText="厂家信息">
            <ItemTemplate>
                <asp:LinkButton ID="btn_viewEnterprise" runat="server"><%#Eval("EnterpriseName") %></asp:LinkButton>

          <asp:HiddenField ID="hidden_eid" runat="server"  Value='<%#Eval("EnterpriseID") %>'/>
            </ItemTemplate>
               <ControlStyle ForeColor="Navy" />
          </asp:TemplateField>
        </Columns>
               <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
               <RowStyle BackColor="#EFF3FB" Font-Size="9pt" Font-Names="宋体" ForeColor="Navy" />
               <EditRowStyle BackColor="#2461BF" />
               <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
               <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Names="宋体" Font-Size="9pt" />
               <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="10pt" />
               <AlternatingRowStyle BackColor="White" />
        </asp:GridView>