javascript
<script type="text/javascript">
var TotalChkBx = 0;
var Counter = 0;
function gridOnLoad(rowCnt) {
TotalChkBx = rowCnt;
Counter = 0;
}
function HeaderClick(CheckBox) {
var TargetBaseControl = document.getElementById('<%= this.egvWPPrint.ClientID %>');
var TargetChildControl = "chkBxSelect";
try {
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
Inputs[n].checked = CheckBox.checked;
Counter = CheckBox.checked ? TotalChkBx : 0;
}
catch (err) {
Counter = 0;
}
}
function ChildClick(CheckBox, HCheckBox) {
try {
var HeaderCheckBox = document.getElementById(HCheckBox);
if (CheckBox.checked && Counter < TotalChkBx)
Counter++;
else if (Counter > 0)
Counter--;
if (Counter < TotalChkBx)
HeaderCheckBox.checked = false;
else if (Counter == TotalChkBx)
HeaderCheckBox.checked = true;
}
catch (err) {
}
}
</script>
c#
// bind after
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "GridLoad", "gridOnLoad(" + ds.Tables[0].Rows.Count.ToString() + ");", true);
protected void egvWPPrint_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chkBxSelect = (CheckBox)e.Row.Cells[1].FindControl("chkBxSelect");
CheckBox chkBxHeader = (CheckBox)this.egvWPPrint.HeaderRow.FindControl("chkBxHeader");
chkBxSelect.Attributes["onclick"] = string.Format
(
"javascript:ChildClick(this,'{0}');",
chkBxHeader.ClientID
);
}
}
aspx
<asp:TemplateField HeaderText="선택">
<ItemTemplate><asp:CheckBox ID="chkBxSelect" runat="server" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
댓글 없음:
댓글 쓰기