byte[] data = FromHex ( "4D657373616765204C696E652032" );
s = Encoding.ASCII.GetString ( data );
public static byte[] FromHex ( string hex )
{
byte[] raw = new byte[hex.Length / 2];
for (int i = 0; i < raw.Length; i++)
{ raw[i] = Convert.ToByte ( hex.Substring ( i * 2, 2 ), 16 ); }
return raw;
}
Monday, August 24, 2009
Friday, May 15, 2009
Use explicit casting instead of DataBinder.Eval to Improve data binding perfomance
The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance.
Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:
<%# DataBinder .Eval(Container.DataItem, "field1") %>
<%# DataBinder .Eval(Container.DataItem, "field2") %>
Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:
<%# ((DataRowView)Container.DataItem)["field1"] %>
<%# ((DataRowView)Container.DataItem)["field2"] %>
Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:
<%# DataBinder .Eval(Container.DataItem, "field1") %>
<%# DataBinder .Eval(Container.DataItem, "field2") %>
Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:
<%# ((DataRowView)Container.DataItem)["field1"] %>
<%# ((DataRowView)Container.DataItem)["field2"] %>
Labels:
Data binding,
Gridview,
Runtime data binding
Subscribe to:
Posts (Atom)