Figure 1 SqlDataNavigator Control in Action
Figure 3 InitializationGridComponent
private void InitializeGridComponent() { // Default settings for pagination
m_grid.AllowCustomPaging = true; m_grid.AllowPaging = true; m_grid.PageSize = 1;
m_grid.Width = Width; m_grid.PagerStyle.Position = PagerPosition.Top; m_grid.PagerStyle.NextPageText
= "4"; m_grid.PagerStyle.PrevPageText = "3"; m_grid.PagerStyle.Font.Name
= "webdings"; m_grid.PagerStyle.Font.Size = FontUnit.Small; m_grid.PagerStyle.ForeColor
= Color.Black; // Other visual default settings m_grid.BackColor = Color.White;
m_grid.BorderWidth = (Unit) 0; m_grid.ForeColor = Color.Black; m_grid.Font.Size
= FontUnit.Point(8); m_grid.Font.Name = "Verdana"; m_grid.CellSpacing
= 0; m_grid.CellPadding = 0; m_grid.HeaderStyle.BackColor = Color.FromName("#3022FF");
m_grid.HeaderStyle.ForeColor = Color.White; m_grid.FooterStyle.Font.Size = FontUnit.XXSmall;
m_grid.FooterStyle.ForeColor = Color.Red; m_grid.ShowFooter = false; m_grid.ShowHeader
= ShowHeader; // Columns #0 (template) m_grid.AutoGenerateColumns = false; TemplateColumn
tc = new TemplateColumn(); tc.ItemTemplate = new DataNavigatorItemTemplate(); tc.EditItemTemplate
= new DataNavigatorEditItemTemplate(); tc.HeaderStyle.BackColor = Color.FromName("#3022FF");
m_grid.Columns.Add(tc); // Column #1 (edit, hidden by default) EditCommandColumn
ecc = new EditCommandColumn(); ecc.Visible = false; ecc.HeaderStyle.Font.Bold =
true; ecc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; ecc.HeaderStyle.ForeColor
= m_grid.ForeColor; ecc.HeaderStyle.BackColor = m_grid.BackColor; ecc.ItemStyle.Font.Bold
= true; ecc.ItemStyle.VerticalAlign = VerticalAlign.Top; ecc.ItemStyle.ForeColor
= LabelForeColor; ecc.ItemStyle.BackColor = LabelBackColor; ecc.ItemStyle.Wrap =
false; ecc.UpdateText = "<br><br>Save"; ecc.CancelText = "<br><br>Cancel";
m_grid.Columns.Add(ecc); // Events m_grid.PageIndexChanged += new DataGridPageChangedEventHandler(OnPageIndexChanged);
m_grid.ItemCreated += new DataGridItemEventHandler(OnItemCreated); m_grid.CancelCommand
+= new DataGridCommandEventHandler(OnCancelCommand); m_grid.UpdateCommand += new
DataGridCommandEventHandler(OnUpdateCommand); }
Figure 4 AddToolbarButtons
private void AddToolbarButtons(ControlCollection ctls) { // Add a separator
from the border or the last control in the // sequence ctls.Add(new LiteralControl(" "));
LinkButton btn; // Add a the NEW linkbutton if (AllowInsert) { btn = new LinkButton();
btn.ForeColor = m_grid.PagerStyle.ForeColor; btn.Text = "à"; btn.Font.Name
= "Wingdings 2"; btn.Font.Bold = true; btn.ID = "_BWSLib_SDN_grid_btnNewRecord_";
btn.ToolTip = "Add a new record"; btn.Click += new EventHandler(OnInsertNewRecord);
ctls.Add(btn); // Add a separator ctls.Add(new LiteralControl(" "));
} // Add a the EDIT linkbutton if (AllowEdit) { btn = new LinkButton(); btn.ForeColor
= m_grid.PagerStyle.ForeColor; btn.Text = "ç"; btn.Font.Name = "Wingdings
3"; btn.Font.Bold = true; btn.ID = "_BWSLib_SDN_grid_btnEditRecord_";
btn.ToolTip = "Edit current record"; btn.Click += new EventHandler(OnEditCurrentRecord);
ctls.Add(btn); // Add a separator ctls.Add(new LiteralControl(" "));
} // Add a the DELETE linkbutton if (AllowDelete) { btn = new LinkButton(); btn.ForeColor
= m_grid.PagerStyle.ForeColor; btn.Text = "r"; btn.Font.Name = "Webdings";
btn.Font.Bold = true; btn.ID = "_BWSLib_SDN_grid_btnDeleteRecord_"; btn.ToolTip
= "Delete current record"; btn.Click += new EventHandler(OnDeleteCurrentRecord);
btn.Attributes["onclick"] = "return confirm('Do you really want to
delete the record?');"; ctls.Add(btn); } }
Figure 5 Editing a Record
Figure 6 Template Class
class DataNavigatorEditItemTemplate : ITemplate { public void InstantiateIn(Control
container) { PlaceHolder ph = new PlaceHolder(); ph.DataBinding += new EventHandler(BindTableColumnsForEdit);
container.Controls.Add(ph); } void BindTableColumnsForEdit(Object sender, EventArgs
e) { PlaceHolder ph = (PlaceHolder) sender; DataGridItem container = (DataGridItem)
ph.NamingContainer; DbDataRecord dbdr = (DbDataRecord) container.DataItem; Table
t = new Table(); ••• ph.Controls.Add(t); } }
Figure 7 DataBoundField
[Serializable] // if not serializable can't go in // viewstate public class
DataBoundField // bound fields are rendered { public bool Visible; // Whether the
field should be // displayed public String FormatText; // How to format the text
public String LabelText; // Text to display to introduce the // field public bool
ReadOnly; // Whether the field is editable or // not public int MultiLineRows; //
Rows through which the (text) // field display public bool Required; // Whether
the field allows NULLs public String DefaultValue; // Text to use when insert a
new // record public ControlType CtlType; // Type of control used to display/ //
edit public String ToolTipText; // Tooltip for the field public BoolFormat BooleanText;
// How to render boolean data public String BoundField; // Name of the field to
bind public String TableName; // Name of the bound table public String DataTextField;
// Name of the field to use for // display public String DataValueField; // Name
of the field to use to join // Class Ctor(s) public DataBoundField() { SetDefaults();
} public DataBoundField(String bf, String t, String dtf, String dvf) { SetDefaults();
// DropDown CtlType = ControlType.DropDown; BoundField = bf; TableName = t; DataTextField
= dtf; DataValueField = dvf; } private void SetDefaults() { Visible = true; // display
the field FormatText = ""; // no special formatting CtlType = ControlType.TextBox;
// use textbox to edit ReadOnly = false; // editable MultiLineRows = 1; // no multi-line
LabelText = ""; // field name ToolTipText = ""; // field type
Required = false; // allows NULL DefaultValue = ""; // default value for
insertions BooleanText = BoolFormat.YesNo; // booleans as YesNo BoundField = "";
TableName = ""; DataTextField = ""; DataValueField = "";
} }
Figure 9 UI of Record Being Edited
|