整合重复代码 生成自定义的列(组件)整合重复代码 生成自定义的datagrid(组件)若要详,整合重复代码,生成自定义的列(组件)整合重复代码,生成自定义的datagrid(组件)若要详
【 tulaoshi.com - ASP.NET 】
描述代码/////////checkboxcolumn.cs////////////////using System;using System.Web;using System.Web.UI.WebControls; namespace MSDN{ /// /// CheckBoxColumn 的摘要说明。 /// public class CheckBoxColumn : DataGridColumn { private string m_allText; public CheckBoxColumn() { CheckBoxAllText="全选"; } public string CheckBoxAllText { get {return m_allText;} set {m_allText = value;} } public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { base.InitializeCell (cell, columnIndex, itemType); if (itemType==ListItemType.Header) { CheckBox chk=new CheckBox(); Label l=new Label(); l.Text=CheckBoxAllText; chk.Attributes.Add("onclick","javascript:SelectAllCheckboxes(this);"); cell.Controls.Add(chk); cell.Controls.Add(l); } if (itemType==ListItemType.Item || itemType==ListItemType.AlternatingItem) { CheckBox chk=new CheckBox(); //chk.CheckedChanged +=new EventHandler(chk_CheckedChanged); chk.AutoPostBack=false; chk.Attributes.Add("onclick","javascript:SelectOneRow(this);"); cell.Controls.Add(chk); } } private void chk_CheckedChanged(object sender, EventArgs e) { //((DataGridItem)((CheckBox)sender).Parent.NamingContainer).ite } }}/////////////SuperDataGrid.cs///////////////using System;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Drawing;using System.Collections;using System.Text;namespace MSDN{ public class SuperDataGrid : System.Web.UI.WebControls.DataGrid { private int m_CreatePageTimes = 0; private Color m_mouseover=Color.Empty; private Color m_mouseout=Color.Empty; private static DataView m_dataview ; public SuperDataGrid():base() { AllowPaging = true; PageIndexChanged+=new DataGridPageChangedEventHandler(HyperDataGrid_PageIndexChanged); ItemCommand +=new DataGridCommandEventHandler(HyperDataGrid_ItemCommand); ItemCreated +=new DataGridItemEventHandler(HyperDataGrid_ItemCreated); ItemDataBound +=new DataGridItemEventHandler(HyperDataGrid_ItemDataBound); SortCommand +=new DataGridSortCommandEventHandler(HyperDataGrid_SortCommand); } public void SetCheckBoxClintScript() { Page.RegisterClientScriptBlock("SelectOneRow",RegisterScript(Color.Pink )); } string RegisterScript(Color color) { StringBuilder str=new StringBuilder(); str.Append(""); return str.ToString(); } //declare dataview public DataView m_DataView { get{return m_dataview;} set{m_dataview=value;} } public Color OnMouseOverColor { get{return m_mouseover;} set{m_mouseover=value;} } public Color OnMouseOutColor { get{return m_mouseout;} set{m_mouseout=value;} } public event EventHandler UpdateView;//fire databinding event public event EventHandler InsertView; private void OnUpdateView() { if (UpdateView != null) UpdateView(this, EventArgs.Empty); } private void OnInsertView() { if (InsertView != null) InsertView(this, EventArgs.Empty); } private void HyperDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { DataGrid detGrid = (DataGrid) source; detGrid.CurrentPageIndex = e.NewPageIndex; m_CreatePageTimes=0; OnUpdateView(); } private void HyperDataGrid_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName=="alpha") { ViewState["alpha"]=e.CommandArgument; m_CreatePageTimes=0; CurrentPageIndex=0; OnUpdateView(); } if (e.CommandName=="Cancle") { ShowFooter=false; } if (e.CommandName=="Insert") { OnInsertView(); ShowFooter=false; } } private void HyperDataGrid_ItemCreated(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType==ListItemType.Header) { //排序 foreach(TableCell c in e.Item.Cells) { if (c.Controls.Count >0 && c.Controls[0].GetType().ToString()=="System.Web.UI.WebControls.DataGridLinkButton") { if (((LinkButton)c.Controls[0]).Text==(string)ViewState["Sort"]) { Label l=new Label(); l.Font.Name="Webdings"; if ((string)ViewState["orderby"]=="asc") l.Text="5"; else l.Text="6"; c.Controls.Add(l); } } } } if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.来源:http://www.tulaoshi.com/n/20160129/1487409.html
看过《整合重复代码 生成自定义的列(组件)整合重复代码 生成自定义的datagrid(组件)若要详》的人还看了以下文章 更多>>