ASP.NET Gridview與checkbox全選、全不選實(shí)現(xiàn)代碼
更新時(shí)間:2010年04月11日 23:51:39 作者:
ASP.NET Gridview checkbox全選與全不選實(shí)現(xiàn)代碼,其實(shí)原理就是利用js來實(shí)現(xiàn)的,但需要簡單的設(shè)置下回傳。
1. 頁面 在onclick事件中 "傳自己"
<asp:TemplateField HeaderText="全選">
<HeaderTemplate>
<input type="checkbox" id="CheckBox1" name="CheckBox1" onclick="GetAllCheckBox(this)" />
全選
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:TemplateField>
2.編寫JS代碼
<script type="text/javascript" language="javascript">
function GetAllCheckBox(CheckAll)
{
var items = document.getElementsByTagName("input");
for(var i=0;i<items.length;i++)
{
if(items[i].type == "checkbox")
{
items[i].checked = CheckAll.checked;
}
}
}
</script>
復(fù)制代碼 代碼如下:
<asp:TemplateField HeaderText="全選">
<HeaderTemplate>
<input type="checkbox" id="CheckBox1" name="CheckBox1" onclick="GetAllCheckBox(this)" />
全選
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:TemplateField>
2.編寫JS代碼
復(fù)制代碼 代碼如下:
<script type="text/javascript" language="javascript">
function GetAllCheckBox(CheckAll)
{
var items = document.getElementsByTagName("input");
for(var i=0;i<items.length;i++)
{
if(items[i].type == "checkbox")
{
items[i].checked = CheckAll.checked;
}
}
}
</script>
您可能感興趣的文章:
- DataGridView中CheckBox實(shí)現(xiàn)某一列單選
- Gridview使用CheckBox全選與單選采用js實(shí)現(xiàn)同時(shí)高亮顯示選擇行
- GridView中加上CheckBox 的全選功能的代碼
- gridview和checkboxlist的嵌套相關(guān)應(yīng)用
- GridView的CheckBox列選擇及多參數(shù)傳遞三步搞定
- asp.net GridView控件中模板列CheckBox全選、反選、取消
- asp.net checkbox 動態(tài)綁定id GridView刪除提示
- Asp.net 中使用GridView控件實(shí)現(xiàn)Checkbox單選
相關(guān)文章
asp.net模板引擎Razor調(diào)用外部方法用法實(shí)例
這篇文章主要介紹了asp.net模板引擎Razor調(diào)用外部方法用法,實(shí)例分析了Razor調(diào)用外部方法的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06Entity?Framework?Core基于數(shù)據(jù)模型創(chuàng)建數(shù)據(jù)庫
這篇文章介紹了Entity?Framework?Core基于數(shù)據(jù)模型創(chuàng)建數(shù)據(jù)庫的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04如何利用HttpClientFactory實(shí)現(xiàn)簡單的熔斷降級
這篇文章主要給大家介紹了關(guān)于如何利用HttpClientFactory實(shí)現(xiàn)簡單的熔斷降級的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07ASP.NET?Core?6.0?添加?JWT?認(rèn)證和授權(quán)功能
這篇文章主要介紹了ASP.NET?Core?6.0?添加?JWT?認(rèn)證和授權(quán),本文將分別介紹?Authentication(認(rèn)證)?和?Authorization(授權(quán)),通過實(shí)例代碼分別介紹了這兩個(gè)功能,需要的朋友可以參考下2022-04-04ASP.NET DropDownListCheckBox使用示例(解決回發(fā)問題)
本文為大家介紹下ASP.NET DropDownListCheckBox的使用,這個(gè)是根據(jù)LigerUI改的,解決了回發(fā)問題,喜歡的朋友可以參考下2013-11-11