📄 checkboxcolumn.cs
字号:
using System;
using System.Collections;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DotNetNuke.Security.Permissions.Controls
{
public delegate void CheckChangedEventHandler(int gridIndex, bool value);
public class CheckBoxColumn : TemplateColumn
{
private CheckChangedEventHandler viewCheckedChangedEvent;
private CheckChangedEventHandler editCheckedChangedEvent;
//----------------------------------------------------------------------------
// Internal storage of the CheckBoxTemplate that is to be used for the view state.
//----------------------------------------------------------------------------
private CheckBoxTemplate viewItem;
//----------------------------------------------------------------------------
// Internal storage of the CheckBoxTemplate that is to be used for the edit state.
//----------------------------------------------------------------------------
private CheckBoxTemplate editItem;
//----------------------------------------------------------------------------
// Initialise our CheckBoxColumn.
//----------------------------------------------------------------------------
public CheckBoxColumn()
{
this.viewItem = new CheckBoxTemplate(true);
this.ItemTemplate = this.viewItem;
// let the edit check box be editable
this.editItem = new CheckBoxTemplate(true);
this.viewItem.BoxCheckedChanged += new CheckChangedEventHandler(OnEditCheckedChanged);
this.EditItemTemplate = this.editItem;
this.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
}
//----------------------------------------------------------------------------
// Initialise our CheckBoxColumn with an optional ImmediatePostback capability.
// If true then each change of state of the CheckBox item
// will cause an event to be fired immediately on the server.
//----------------------------------------------------------------------------
public CheckBoxColumn(bool immediatePostback, string trueValue)
{
// set the view one as readonly
this.viewItem = new CheckBoxTemplate(immediatePostback, trueValue);
this.viewItem.BoxCheckedChanged += new CheckChangedEventHandler(OnViewCheckedChanged);
this.ItemTemplate = this.viewItem;
// let the edit check box be editable
this.editItem = new CheckBoxTemplate(!immediatePostback, trueValue);
this.editItem.BoxCheckedChanged += new CheckChangedEventHandler(OnEditCheckedChanged);
this.EditItemTemplate = this.editItem;
this.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
AutoPostBack = immediatePostback;
}
//----------------------------------------------------------------------------
// If true then then each click on a CheckBox will cause an event to be fired on the server.
//----------------------------------------------------------------------------
public bool AutoPostBack
{
get { return this.viewItem.AutoPostBack; }
set
{
this.viewItem.AutoPostBack = value;
this.editItem.AutoPostBack = value;
}
}
public event CheckChangedEventHandler ViewCheckedChanged
{
add { this.viewCheckedChangedEvent += value; }
remove { this.viewCheckedChangedEvent -= value; }
}
public event CheckChangedEventHandler EditCheckedChanged
{
add { this.editCheckedChangedEvent += value; }
remove { this.editCheckedChangedEvent -= value; }
}
public void OnEditCheckedChanged (int gridIndex, bool value)
{
if (this.editCheckedChangedEvent != null)
this.editCheckedChangedEvent(gridIndex, value);
}
public void OnViewCheckedChanged (int gridIndex, bool value)
{
if (this.viewCheckedChangedEvent != null)
this.viewCheckedChangedEvent(gridIndex, value);
}
//----------------------------------------------------------------------------
// The DataField that we wish our control to bind to.
//----------------------------------------------------------------------------
public string DataField
{
get { return this.viewItem.DataField; }
set
{
this.viewItem.DataField = value;
this.editItem.DataField = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -