Benefits
1 - Standard of software factory
2 - Visual inheritance (your controls childs inherits the bahivor and visual design
3 - Standard of code
4 - Over reutilization
Conclusion
Highly indicated for it manufactures of software
Step 1
Create WebControlLibrary and add source code
To personalize all the functionalities of its grid, for example
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.IO;
using System.Drawing;
namespace Personal.Web.UI.WebControls
{
public class DataGrid :System.Web.UI.WebControls.DataGrid
{
public DataGrid()
{
}
protected override void Render(HtmlTextWriter output)
{
this.AutoGenerateColumns = false;
this.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
this.GridLines = GridLines.Both;
this.SelectedItemStyle.Font.Name = "Tahoma";
this.SelectedItemStyle.Font.Size = 8;
this.SelectedItemStyle.Font.Bold = true;
this.SelectedItemStyle.ForeColor = System.Drawing.Color.White;
this.SelectedItemStyle.BackColor = System.Drawing.Color.FromName("#000099");
this.AlternatingItemStyle.Font.Name = "Tahoma";
this.AlternatingItemStyle.Font.Size = 8;
this.AlternatingItemStyle.ForeColor = System.Drawing.Color.Black;
this.AlternatingItemStyle.BackColor = System.Drawing.Color.WhiteSmoke;
this.ItemStyle.Font.Name = "Tahoma";
this.ItemStyle.Font.Size = 8;
this.ItemStyle.ForeColor = System.Drawing.Color.Black;
this.ItemStyle.BackColor = System.Drawing.Color.White;
this.HeaderStyle.Font.Name = "Tahoma";
this.HeaderStyle.Font.Size = 8;
this.HeaderStyle.Font.Bold = true;
this.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
this.PagerStyle.Font.Name = "Tahoma";
this.PagerStyle.Font.Size = 8;
this.PagerStyle.BackColor = System.Drawing.Color.DarkGray;
this.AllowPaging = true;
this.PagerStyle.Mode = PagerMode.NumericPages;
this.PagerStyle.HorizontalAlign = HorizontalAlign.Center;
base.Render(output);
}
#region Public Aux Objects
TextBox txt = null;
DropDownList ddl = null;
CheckBox chk = null;
Image img = null;
int record ;
#endregion
#region Methods
public void DataBindObjects(DataGrid dg,DataSet ds,int pageindex,int pagesize)
{
int i = 0;
int ids = 0;
if (this.editable == null ||
this.objectname == null ||
this.fieldname == null ||
this.editable.Count != this.fieldname.Count ||
this.editable.Count != this.objectname.Count ||
this.fieldname.Count != this.editable.Count ||
this.fieldname.Count != this.objectname.Count ||
this.objectname.Count != this.fieldname.Count ||
this.objectname.Count != this.editable.Count )
{
string msg = "n";
msg += "DropDown,TextBox e CheckBox :\n";
msg += "c.FieldName = 'Field'\n";
msg += "c.ObjectName = 'TextBox3'\n";
msg += "c.Editable = true\n ";
msg += " 'c' ";
throw new Exception(msg);
}
for (ids=0;ids<dg.Items.Count;ids++)
{
DataGridItem dgi = dg.Items[ids];
record = (pagesize * pageindex) + ids;
for (i=0;i<this.fieldname.Count;i++)
{
object obj = dgi.FindControl(this.objectname[i].ToString());
if (obj is TextBox)
{
txt = (TextBox) dgi.FindControl(this.objectname[i].ToString());
if (this.editable != null)
{
if ((bool)this.editable[i] == true)
{
txt.ReadOnly = false;
}
else
{
txt.ReadOnly = true;
}
}
else
{
txt.Enabled = true;
}
}
else if (obj is Image)
{
img = (Image) dgi.FindControl(this.objectname[i].ToString());
}
else if (obj is DropDownList)
{
ddl = (DropDownList) dgi.FindControl(this.objectname[i].ToString());
if (this.editable != null)
{
if ((bool)this.editable[i] == true)
{
ddl.Enabled = true;
}
else
{
ddl.Enabled = false;
}
}
else
{
ddl.Enabled = true;
}
}
else if (obj is CheckBox)
{
chk = (CheckBox) dgi.FindControl(this.objectname[i].ToString());
if (this.editable != null)
{
if ((bool)this.editable[i] == true)
{
chk.Enabled = true;
}
else
{
chk.Enabled = false;
}
}
else
{
chk.Enabled = true;
}
}
}
i=0;
for (i=0;i<this.fieldname.Count;i++)
{
if (txt !=null && this.objectname[i].ToString().ToUpper() == txt.ID.ToUpper())
{
txt.Text = ds.Tables[0].Rows[record]
[this.fieldname[i].ToString()].ToString();
}
else if (img !=null && this.objectname[i].ToString().ToUpper()
== img.ID.ToUpper())
{
try
{
byte[] bits = (byte[]) ds.Tables[0].Rows[record]
[this.fieldname[i].ToString()];
MemoryStream memorybits = new MemoryStream(bits);
System.Drawing.Image bitmap = System.Drawing.Image.FromStream(memorybits);
string imageharddisk = @"c:\temp\img\" + (img.GetHashCode() + i);
bitmap.Save(imageharddisk);
img.ImageUrl = imageharddisk;
}
catch
{
}
}
else if (ddl !=null && this.objectname[i].ToString().ToUpper()
== ddl.ID.ToUpper())
{
if(this.DataFieldText == null |
this.DataFieldValue == null)
{
throw new NullReferenceException("DataFieldText ou DataFieldValue, não pode ser nulo");
}
ddl.DataTextField = this.DataFieldText;
ddl.DataValueField = this.DataFieldValue;
if (this.dropdowndata == null)
{
throw new NullReferenceException("DropDownData, não pode ser nulo");
}
ddl.DataSource = (DataSet) this.dropdowndata[i];
ddl.DataBind();
this.PositionObjectList(
ddl,
ds.Tables[0].Rows[record][this.fieldname[i].ToString()].ToString());
}
else if (chk !=null && this.objectname[i].ToString().ToUpper()
== chk.ID.ToUpper())
{
if (ds.Tables[0].Rows[record][this.fieldname[i].ToString()].ToString().Trim() == "0")
{
chk.Checked = false;
}
else
{
chk.Checked = true;
}
}
}
}
}
public void PositionObjectList(DropDownList objectlist ,
string val)
{
int i;
for (i = 0;i < (objectlist.Items.Count);i++)
{
objectlist.SelectedIndex = i;
if (objectlist.SelectedItem.Value == val)
{
objectlist.SelectedItem.Selected = true;
break;
}
}
}
public void PositionObjectList(ListBox objectlist ,
string val)
{
int i;
for (i = 0;i < (objectlist.Items.Count);i++)
{
objectlist.SelectedIndex = i;
if (objectlist.SelectedItem.Value == val)
{
objectlist.SelectedItem.Selected = true;
break;
}
}
}
#endregion
#region Properties
private ArrayList fieldname;
private ArrayList objectname;
private ArrayList editable;
private ArrayList dropdowndata;
private string datafieldtext;
private string datafieldvalue;
public string DataFieldText
{
set
{
datafieldtext = value;
}
get
{
return datafieldtext;
}
}
public string DataFieldValue
{
set
{
datafieldvalue = value;
}
get
{
return datafieldvalue ;
}
}
public DataSet DropDownData
{
set
{
if (dropdowndata == null)
{
dropdowndata = new ArrayList();
}
dropdowndata .Add (value);
}
}
public string FieldName
{
set
{
if (fieldname == null)
{
fieldname = new ArrayList();
}
fieldname.Add (value);
}
}
public string ObjectName
{
set
{
if (objectname == null)
{
objectname = new ArrayList();
}
objectname.Add(value);
}
}
public bool Editable
{
set
{
if (editable == null)
{
editable = new ArrayList();
}
editable.Add(value);
}
}
#endregion
}
}
The Key is Standard for your Software Factory
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.