添加clientidmode =" Static"后,SelectAll复选框无效。在C#中 [英] SelectAll checkbox is not working after added clientidmode="Static" in C#
本文介绍了添加clientidmode =" Static"后,SelectAll复选框无效。在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网格视图中有复选框。当我选择selectall复选框时,它不会选中所有复选框。请参阅下面的代码。当我添加clientidmode =Static之后,SelectAll检查没有发生。
Java脚本代码 - -
Hi,
I have checkbox in grid view. when i m selecting selectall checkbox, its not selecting all checkbox. Please see my code in below.When i added clientidmode="Static", after that SelectAll check is not happening.
Java script code---
function SelectAll(obj, gridViewID, chk) {
var blres;
var gridView = document.getElementById(gridViewID);
var gridViewControls = gridView.getElementsByTagName("input");
if(obj.checked)
{
blres = true;
}
else
{
blres = false;
}
var getid = (obj.id).split("_");
var chkHeaderBoxID = getid[2];
for(i=0; i< gridViewControls.length; i++)
{
if(gridViewControls[i].type == "checkbox" && gridViewControls[i].id.indexOf(chk) >0)
{
gridViewControls[i].checked = blres;
}
}
}
Aspx代码 -
Aspx Code--
<asp:TemplateField ItemStyle-VerticalAlign="Top" ItemStyle-Width="1px">
<HeaderTemplate>
<input type="checkbox" id="chkDeleteAll" runat="server" name="chkDeleteAll" clientidmode="Static">
<%-- <input type="checkbox" id="chkDeleteAll" runat="server" name="chkDeleteAll" align="left" />--%>
</HeaderTemplate>
<itemtemplate>
<input type="checkbox" id="chkDelete" runat="server" name="chkDelete" clientidmode="Static">
<%--<input type="checkbox" id="chkDelete" runat="server" name="chkDelete" önclik="chkit(this)"
align="left" />--%>
</itemtemplate>
Aspx.CS代码
Aspx.CS code
protected void gvPastThreeyears_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
HtmlInputCheckBox chkbox;
if (e.Row.RowType == DataControlRowType.Header)
{
chkbox = (HtmlInputCheckBox)e.Row.FindControl("chkDeleteAll");
strHeaderCheckBoxId = chkbox.ClientID;
if (!btnSavePastThreeyears.Visible)
{
chkbox.Disabled = true;
}
else
{
chkbox.Attributes.Add("OnClick", "Javascript:SelectAll(this,'" + gvPastThreeyears.ClientID + "','chkDelete');");
}
}
else if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.DataRow)
{
chkbox = (HtmlInputCheckBox)e.Row.FindControl("chkDelete");
TextBox txtPastInvestment = null;
txtPastInvestment = (TextBox)e.Row.FindControl("txtPastInvestment");
if (!btnSavePastThreeyears.Visible)
{
DropDownList ddlPastItem = (DropDownList)e.Row.FindControl("ddlPastItem");
ddlPastItem.Enabled = false;
TextBox txtPastSummaryDescription = (TextBox)e.Row.FindControl("txtPastSummaryDescription");
txtPastSummaryDescription.ReadOnly = true;
txtPastInvestment.ReadOnly = true;
//ddlPastYear
DropDownList ddlPastYear = (DropDownList)e.Row.FindControl("ddlPastYear");
ddlPastYear.Enabled = false;
chkbox.Disabled = true;
}
else
{
chkbox.Attributes.Add("OnClick", "Javascript:UnSelect(this,'" + strHeaderCheckBoxId + "','" + gvPastThreeyears.ClientID + "');");
txtPastInvestment.Attributes.Add("onKeypress", "javascript:return IsDecimal(this)");
}
}
}
推荐答案
嗨Kamalsekhar,
请使用以下代码检查/取消选中gridview中的所有复选框。
Hi Kamalsekhar,
Please use following code to check/uncheck all checkboxes inside the gridview.
( document )。ready( function (){
(document).ready(function() {
(< span class =code-string>' #gvPastThreeyears')。find(' #chkDeleteAll')。click( function (){
var isChecked =
('#gvPastThreeyears').find('#chkDeleteAll').click(function(){ var isChecked =
这篇关于添加clientidmode =" Static"后,SelectAll复选框无效。在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文