自定义删除组合按钮
在项目中,把删除的组合按钮都写成一个控件,这样子我就不会再每个都写了,只要直接拉进页面就OK啦
呵呵,感觉方便多了
呵呵,感觉方便多了
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace WebClass
{
public class ControlOfDel:Control,INamingContainer
{
private string _gridview1ID;
private string _checkBoxID;
[Browsable(true)]
[Description("要删除的选择")]
[Category("扩展")]
[DefaultValue("")]
public event EventHandler delSelect;
[Browsable(true)]
[Description("要删除所有")]
[Category("扩展")]
[DefaultValue("")]
public event EventHandler delAll;
[Browsable(true)]
[Description("设置要查找的GridView控件的id")]
[Category("扩展")]
[DefaultValue("GridView1")]
public string GridviewID
{
get
{
return _gridview1ID;
}
set
{
_gridview1ID = value;
}
}
[Browsable(true)]
[Description("设置要查找的CheckBox控件的id")]
[Category("扩展")]
[DefaultValue("")]
public string CheckboxID
{
get
{
return _checkBoxID;
}
set
{
_checkBoxID = value;
}
}
protected override void CreateChildControls()
{
LinkButton selectAllButton = new LinkButton();
selectAllButton.Text = "全选";
this.Controls.Add(selectAllButton);
selectAllButton.Click += new EventHandler(selectAllButton_clicked);
Literal liter1 = new Literal();
liter1.Text = " ";
this.Controls.Add(liter1);
LinkButton reSelectAllButton = new LinkButton();
reSelectAllButton.Text = "反选";
this.Controls.Add(reSelectAllButton);
reSelectAllButton.Click += new EventHandler(reSelectAllButton_clicked);
Literal liter2 = new Literal();
liter2.Text = " ";
this.Controls.Add(liter2);
LinkButton SelectCannel = new LinkButton();
SelectCannel.Text = "取消";
this.Controls.Add(SelectCannel);
SelectCannel.Click += new EventHandler(selectCannel_clicked);
Literal liter3 = new Literal();
liter3.Text = " ";
this.Controls.Add(liter3);
LinkButton DelOfSelect = new LinkButton();
DelOfSelect.Text = "删除选择";
this.Controls.Add(DelOfSelect);
DelOfSelect.Click+=new EventHandler(DelOfSelect_Click);
Literal liter4 = new Literal();
liter4.Text = " ";
this.Controls.Add(liter4);
LinkButton DelOfAll = new LinkButton();
DelOfAll.Text = "删除所有";
this.Controls.Add(DelOfAll);
DelOfAll.Click+=new EventHandler(DelOfAll_Click);
base.CreateChildControls();
}
protected void DelOfSelect_Click(object sender, EventArgs e)
{
if (delSelect != null)
{
delSelect(this, e);
}
}
protected void DelOfAll_Click(object sender, EventArgs e)
{
if (delAll != null)
{
delAll(this, e);
}
}
private GridView GridView1;// = (GridView)this.Page.FindControl(_gridview1Name);
private void selectAllButton_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = true;
}
}
protected void reSelectAllButton_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = !CheckBox1.Checked;
}
}
protected void selectCannel_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = false;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls();
base.Render(writer);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace WebClass
{
public class ControlOfDel:Control,INamingContainer
{
private string _gridview1ID;
private string _checkBoxID;
[Browsable(true)]
[Description("要删除的选择")]
[Category("扩展")]
[DefaultValue("")]
public event EventHandler delSelect;
[Browsable(true)]
[Description("要删除所有")]
[Category("扩展")]
[DefaultValue("")]
public event EventHandler delAll;
[Browsable(true)]
[Description("设置要查找的GridView控件的id")]
[Category("扩展")]
[DefaultValue("GridView1")]
public string GridviewID
{
get
{
return _gridview1ID;
}
set
{
_gridview1ID = value;
}
}
[Browsable(true)]
[Description("设置要查找的CheckBox控件的id")]
[Category("扩展")]
[DefaultValue("")]
public string CheckboxID
{
get
{
return _checkBoxID;
}
set
{
_checkBoxID = value;
}
}
protected override void CreateChildControls()
{
LinkButton selectAllButton = new LinkButton();
selectAllButton.Text = "全选";
this.Controls.Add(selectAllButton);
selectAllButton.Click += new EventHandler(selectAllButton_clicked);
Literal liter1 = new Literal();
liter1.Text = " ";
this.Controls.Add(liter1);
LinkButton reSelectAllButton = new LinkButton();
reSelectAllButton.Text = "反选";
this.Controls.Add(reSelectAllButton);
reSelectAllButton.Click += new EventHandler(reSelectAllButton_clicked);
Literal liter2 = new Literal();
liter2.Text = " ";
this.Controls.Add(liter2);
LinkButton SelectCannel = new LinkButton();
SelectCannel.Text = "取消";
this.Controls.Add(SelectCannel);
SelectCannel.Click += new EventHandler(selectCannel_clicked);
Literal liter3 = new Literal();
liter3.Text = " ";
this.Controls.Add(liter3);
LinkButton DelOfSelect = new LinkButton();
DelOfSelect.Text = "删除选择";
this.Controls.Add(DelOfSelect);
DelOfSelect.Click+=new EventHandler(DelOfSelect_Click);
Literal liter4 = new Literal();
liter4.Text = " ";
this.Controls.Add(liter4);
LinkButton DelOfAll = new LinkButton();
DelOfAll.Text = "删除所有";
this.Controls.Add(DelOfAll);
DelOfAll.Click+=new EventHandler(DelOfAll_Click);
base.CreateChildControls();
}
protected void DelOfSelect_Click(object sender, EventArgs e)
{
if (delSelect != null)
{
delSelect(this, e);
}
}
protected void DelOfAll_Click(object sender, EventArgs e)
{
if (delAll != null)
{
delAll(this, e);
}
}
private GridView GridView1;// = (GridView)this.Page.FindControl(_gridview1Name);
private void selectAllButton_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = true;
}
}
protected void reSelectAllButton_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = !CheckBox1.Checked;
}
}
protected void selectCannel_clicked(Object sender, EventArgs e)
{
GridView1 = (GridView)this.Page.FindControl(_gridview1ID);
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)this.GridView1.Rows[i].FindControl(_checkBoxID.Trim());
CheckBox1.Checked = false;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls();
base.Render(writer);
}
}
}