ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

SetLiteralText

Often you have to set the text of lots of literal when databinding a ListView control in ASP.Net. This method lets you write that in one line.

Source

public static void SetLiteralText(this ListViewItem item, string literalName, string text)
{
  Literal literal = (Literal)item.FindControl(literalName);
  literal.Text = text;
}

Example

void ListView_ItemDataBound(object sender,
                            ListViewItemEventArgs e)
{
  e.Item.SetLiteralText("RandomLiteral",
                        "Text For Literal");
}

Author: Timmy Kokke

Submitted on: 16 jul 2010

Language: C#

Type: System.Web.UI.WebControls.ListViewItem

Views: 2480