标题gridview中的复选框 [英] checkbox in header gridview
本文介绍了标题gridview中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 场景
--scenario
<asp:GridView ID="GridZeroApprovedKm" AllowPaging="true" runat="server" AutoGenerateColumns="false"
DataKeyNames="Address_id" OnRowCancelingEdit="GridZeroApprovedKm_RowCancelingEdit"
OnRowDataBound="GridZeroApprovedKm_RowDataBound" OnRowDeleting="GridZeroApprovedKm_RowDeleting"
OnRowEditing="GridZeroApprovedKm_RowEditing" OnRowUpdating="GridZeroApprovedKm_RowUpdating">
<SelectedRowStyle CssClass="ResultSelectedRow" BackColor="Cyan" />
<columns>
<%-- hub_name,address_id,geocode_address--%>
<asp:TemplateField HeaderText="Select All">
<HeaderTemplate>
<asp:CheckBox ID="chkb1" runat="server" Text="Select All" OnCheckedChanged="sellectAll"
AutoPostBack="true" />
</HeaderTemplate>
<itemstyle horizontalalign="Center" verticalalign="Middle" />
<itemtemplate>
<asp:CheckBox ID="chkb2" runat="server" Text="Select" />
</itemtemplate>
<itemstyle horizontalalign="center" />
---代码背后
---code behind
protected void sellectAll(object sender, EventArgs e)
{
CheckBox ChkBoxHeader = (CheckBox)GridZeroApprovedKm.HeaderRow.FindControl("chkb1");
foreach (GridViewRow row in GridZeroApprovedKm.Rows)
{
CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkb2");
if (ChkBoxHeader.Checked == true)
{
ChkBoxRows.Checked = true;
}
else
{
ChkBoxRows.Checked = false;
}
}
}
- 当我点击标题复选框时
- 检查gridview的所有复选框....但页面刷新....我已将autopostback属性设为true。为什么刷新?
--when i click the header checkbox
--it checks all the checkbox of the gridview....but the page is refreshed....i have made the autopostback property as true. Why does it refresh ?
推荐答案
Hii ...
看到这个,它可能对你有帮助。
在aspx中
Hii...
See this one,its may helpful to u.
In aspx
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
(document).ready(function(){
(document).ready(function () {
('[id * = chkHeader]')。click(function(){
('[id*=chkHeader]').click(function () {
这篇关于标题gridview中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文