in the Item Template do exactly?-datalist">

[ACCEPTED]-What does <%# DataBinder.Eval(Container.DataItem,"ColumnName") %> in the Item Template do exactly?-datalist

Accepted answer
Score: 18

Argument 1: Container.DataItem refers to the datasource that is bound 5 to the current container.

Argument 2: The 4 public property on the DataItem which should be 3 evaluated.

So Eval uses reflection to evaluate 2 the public property on the DataItem.

ex:

In you 1 case it evaluates the BB column on the DataTable.

Score: 9

The following lines will be executed as 5 many times as the number of rows in the 4 Table.

<%# DataBinder.Eval(Container.DataItem,"AA") %>
<%# DataBinder.Eval(Container.DataItem,"BB") %>
<%# DataBinder.Eval(Container.DataItem,"CC") %>

Each time Container.DataItem will have the corresponding 3 DataRowView of the rows in the datatable.

What happens 2 in the item is similar to this code.

DataView dataView = new DataView(dt);
foreach (DataRowView dataRow in dataView)
{              
    System.Diagnostics.Debug.WriteLine(DataBinder.Eval(dataRow,"AA").ToString());
    System.Diagnostics.Debug.WriteLine(DataBinder.Eval(dataRow,"BB").ToString());
    System.Diagnostics.Debug.WriteLine(DataBinder.Eval(dataRow,"CC").ToString());
}

And 1 the output obtained will be

1 2 3 10 20 30 100 200 300 1000 2000 3000

More Related questions