How to develop a user control?
-
I get a example of FixedDataGrid Written by Alexander Zeitler.His example work well.It is fixed datagrid row height.I want to add some other function to it,such as highlight entire row,The highlight row work well,but the delete ,edit ,update command work failed! the all code is here,Can anyone give some help? using System; using System.IO; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; //using CustomControls; namespace WinDataGrid { public class FixedHeightGrid : System.Web.UI.WebControls.DataGrid { private bool _mergePaddingColumns; private TableItemStyle _paddingItemStyle = new TableItemStyle(); private int _RowHeight = 22; private string _sRowForColor = "white"; private string _sRowBackColor = "lightblue"; public FixedHeightGrid() { this.ShowFooter=false; this.ShowHeader=true; this.AllowPaging=true; } public bool MergePaddingColumns { get {return _mergePaddingColumns;} set {_mergePaddingColumns = value;} } public TableItemStyle PaddingItemStyle { get {return _paddingItemStyle;} set {_paddingItemStyle = value;} } public int RowHeight { get { return _RowHeight;} set {_RowHeight = value;} } public string RowForColor { get { return _sRowForColor;} set {_sRowForColor = value;} } public string RowBackColor { get { return _sRowBackColor;} set {_sRowBackColor = value;} } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); AddPaddingItems(); } protected override void OnItemCreated(DataGridItemEventArgs e) { base.OnItemCreated(e); if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { e.Item.Attributes.Add("OnMouseOver", "this.style.backgroundColor = '" + _sRowBackColor + "';"); e.Item.Attributes.Add("OnMouseOut", "this.style.backgroundColor = '" + _sRowForColor + "';"); } } private void AddPaddingItems() { int indexCount; int indexStop = this.PageSize; int indexStart = 1; if(this.AllowPaging==true) { indexStart++; indexStop++; } Table myTable = (Table)this.Controls[0]; for(indexCount=indexStart+this.Items.Count;indexCount<=indexStop;indexCount++) { myTable.Controls.AddAt(indexCount,PaddingItem()); } } private DataGridItem PaddingItem() { DataGridItem myItem = new DataGridItem(0,0,ListItemType.Item)
-
I get a example of FixedDataGrid Written by Alexander Zeitler.His example work well.It is fixed datagrid row height.I want to add some other function to it,such as highlight entire row,The highlight row work well,but the delete ,edit ,update command work failed! the all code is here,Can anyone give some help? using System; using System.IO; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; //using CustomControls; namespace WinDataGrid { public class FixedHeightGrid : System.Web.UI.WebControls.DataGrid { private bool _mergePaddingColumns; private TableItemStyle _paddingItemStyle = new TableItemStyle(); private int _RowHeight = 22; private string _sRowForColor = "white"; private string _sRowBackColor = "lightblue"; public FixedHeightGrid() { this.ShowFooter=false; this.ShowHeader=true; this.AllowPaging=true; } public bool MergePaddingColumns { get {return _mergePaddingColumns;} set {_mergePaddingColumns = value;} } public TableItemStyle PaddingItemStyle { get {return _paddingItemStyle;} set {_paddingItemStyle = value;} } public int RowHeight { get { return _RowHeight;} set {_RowHeight = value;} } public string RowForColor { get { return _sRowForColor;} set {_sRowForColor = value;} } public string RowBackColor { get { return _sRowBackColor;} set {_sRowBackColor = value;} } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); AddPaddingItems(); } protected override void OnItemCreated(DataGridItemEventArgs e) { base.OnItemCreated(e); if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { e.Item.Attributes.Add("OnMouseOver", "this.style.backgroundColor = '" + _sRowBackColor + "';"); e.Item.Attributes.Add("OnMouseOut", "this.style.backgroundColor = '" + _sRowForColor + "';"); } } private void AddPaddingItems() { int indexCount; int indexStop = this.PageSize; int indexStart = 1; if(this.AllowPaging==true) { indexStart++; indexStop++; } Table myTable = (Table)this.Controls[0]; for(indexCount=indexStart+this.Items.Count;indexCount<=indexStop;indexCount++) { myTable.Controls.AddAt(indexCount,PaddingItem()); } } private DataGridItem PaddingItem() { DataGridItem myItem = new DataGridItem(0,0,ListItemType.Item)
You need to check out Event Bubbling: http://www.odetocode.com/Articles/94.aspx
-
You need to check out Event Bubbling: http://www.odetocode.com/Articles/94.aspx
-
You need to check out Event Bubbling: http://www.odetocode.com/Articles/94.aspx
-
You need to check out Event Bubbling: http://www.odetocode.com/Articles/94.aspx