Asked by:
Understanding inherit ITemplate

Question
-
User-1004886483 posted
I have this inherit (interface System.Web.UI.ITemplate)
: ITemplate
to my class... why this inherit has been done? and what will afect in this class?
CheckBoxItem.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Configuration; //[Serializable] [Serializable()] public class CheckBoxItem : ITemplate { /// <summary> /// The CheckBoxItem constructor /// </summary> /// <param name="editable">true if the item is to be in its editable state, false for the item to be disabled.</param> public CheckBoxItem(bool editable) { readOnly = (editable == true) ? false : true; } /// <summary> /// Instantiates the CheckBox that we wish to represent in this column. /// </summary> /// <param name="container">The container into which the control or controls are added.</param> void ITemplate.InstantiateIn(Control container) { CheckBox box = new CheckBox(); box.DataBinding += new EventHandler(this.BindData); box.AutoPostBack = autoPostBack; box.CheckedChanged += new EventHandler(this.OnCheckChanged); container.Controls.Add(box); } /// <summary> /// Our CheckChanged event /// </summary> public event EventHandler CheckedChanged; /// <summary> /// This is a common handler for all the Checkboxes. /// </summary> /// <param name="sender">The raiser of this event a CheckBox.</param> /// <param name="e">A System.EventArgs that contains the event data.</param> public void OnCheckChanged(object sender, EventArgs e) { if (CheckedChanged != null) { CheckedChanged(sender, e); } } // private void OnCheckChanged(object sender, EventArgs e) //{ // CheckBox box = (CheckBox) sender; //DataGridItem container = (DataGridItem) box.NamingContainer; // sqlUpdateCommand1.Parameters["@Object_id"].Value // = int.Parse(container.Cells[0].Text); // sqlUpdateCommand1.Parameters["@Boolean"].Value = box.Checked; // ... // // } /// <summary> /// The internal storage for which DataField we are going to represent. /// </summary> private string dataField; /// <summary> /// Used to set the DataField that we wish to represent with this CheckBox. /// </summary> public string DataField { get { return dataField; } set { dataField = value; } } private string val; public string Val { get { return val; } set { val = value; } } /// <summary> /// The internal storage for the AutoPostback flag. /// </summary> private bool autoPostBack = false; /// <summary> /// Set the AutoPostBack flag. If this is true then each time a CheckBox is clicked /// in the Column that contains this item then an event is raised on the server. /// </summary> public bool AutoPostBack { set { autoPostBack = value; } get { return autoPostBack; } } /// <summary> /// Handler for the DataBinding event where we bind the data for a specific row /// to the CheckBox. /// </summary> /// <param name="sender">The raiser of the event.</param> /// <param name="e">A System.EventArgs that contains the event data.</param> private void BindData(object sender, EventArgs e) { CheckBox box = (CheckBox)sender; DataGridItem container = (DataGridItem)box.NamingContainer; box.Checked = false; box.Enabled = (readOnly == true) ? false : true; if (dataField != string.Empty) { string data = string.Empty; Type t = null; if (dataField.ToLower() == ConfigurationSettings.AppSettings["GridPK"].ToLower()) { data = container.Cells[0].Text; t = typeof(string); } else { data = ((DataRowView)container.DataItem)[dataField].ToString(); t = ((DataRowView)container.DataItem).DataView.Table.Columns[dataField].DataType; } if (data.Length > 0) { switch (t.ToString()) { case "System.Boolean": if ((data == "True") || (data == "true")) { box.Checked = true; } break; case "System.String": box.ToolTip = data; break; default: break; } } } } /// <summary> /// Internal storage for the readOnly flag. /// </summary> private bool readOnly = true; }
Friday, December 15, 2017 10:37 AM
All replies
-
User347430248 posted
Hi devquestions...,
if ITemplate is inherited to your class then you can use the functionality of that class in to your class.
this is the concept of inheritance.
One of the most important concepts in object-oriented programming is inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
The idea of inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.
Reference:
Regards
Deepak
<sub></sub><sup></sup><sub></sub><sup></sup><sub></sub><sup></sup>
Monday, December 18, 2017 9:04 AM -
User-1004886483 posted
Hi,
thanks for your answer, for this case, can you tell me what i accutally use in my CheckBoxItem of ITemplate Class?
Thanks
Monday, December 18, 2017 10:55 AM -
User347430248 posted
Hi devquestions...,
you had asked,"can you tell me what i accutally use in my CheckBoxItem of ITemplate Class?"
you can directly go to the ITemplate class and find the methods and properties and check in your derived class.
since you did not posted the ITemplate class.
so we don't know that what is inside that class.
so you need to check it by your own.
let us know if you have any difficulty in that. we will try to provide you further suggestions to solve the issue.
Thanks for your understanding.
Regards
Deepak
<sub></sub><sup></sup><sub></sub><sup></sup><sub></sub><sup></sup>
Tuesday, December 19, 2017 8:18 AM -
User-1004886483 posted
Hi,
the ITemplate in fact is :
Interface System.Web.UI.ITemplate
Wednesday, December 20, 2017 2:06 PM -
User347430248 posted
Hi devquestions...,
Defines the method to implement for populating an ASP.NET server control with child controls when using a control with inline templates when declared in an .aspx file.
This interface is used by custom server controls, but never implemented by them. ASP.NET always implements it.
you can find the example in link below.
Regards
Deepak
<sub></sub><sup></sup><sub></sub><sup></sup><sub></sub><sup></sup>
Monday, December 25, 2017 8:16 AM