Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I normaly use ItemTemplates that inherit from ITemplate. With in the ItemTemplate I use the SPFieldxxxValue classes or some custom formating code. This saves looping through the DataTable and the ItemTemplates can be reused.</p> <p>The ItemTemplates are attached in Column Binding E.G</p> <pre><code>// Normal Data Binding SPBoundField fld = new SPBoundField(); fld.HeaderText = field.DisplayName; fld.DataField = field.InternalName; fld.SortExpression = field.InternalName; grid.Columns.Add(fld); // ItemTemplate Binding TemplateField fld = new TemplateField(); fld.HeaderText = field.DisplayName; fld.ItemTemplate = new CustomItemTemplateClass(field.InternalName); fld.SortExpression = field.InternalName; grid.Columns.Add(fld); </code></pre> <p>An example of a ItemTemplate</p> <pre><code>public class CustomItemTemplateClass : ITemplate { private string FieldName { get; set; } public CustomItemTemplateClass(string fieldName, string formatString) { FieldName = fieldName; } #region ITemplate Members public void InstantiateIn(Control container) { Literal lit = new Literal(); lit.DataBinding += new EventHandler(lit_DataBinding); container.Controls.Add(lit); } #endregion void lit_DataBinding(object sender, EventArgs e) { Literal lit = (Literal)sender; SPGridViewRow container = (SPGridViewRow)lit.NamingContainer; string fieldValue = ((DataRowView)container.DataItem)[FieldName].ToString(); //Prosses Filed value here SPFieldLookupValue lookupValue = new SPFieldLookupValue(fieldValue); //Display new value lit.Text = lookupValue.LookupValue; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload