Binding

  • Thread starter Thread starter Lubomir
  • Start date Start date
L

Lubomir

Hi,

I have a gridview with tepmlate and boundfield columns.

Two of columns are defined as follow:
<asp:BoundField HeaderText="Test" ...../>
<asp:TemplateField>
<ItemTemplate>
<%# MyMethod(Eval("Test")) %>
</ItemTemplate>
</asp:TemplateField>

The column in a template field takes value from the Test column and returns
some new value, showing it in the gridview.

In the Page_Load (!IsPostback) I am renaming the bound column header "Test"
to other name and at the end I call DataBind. I expected the template item
will not be evaluated properly, as the header text "Test" doesn't exists
anymore, but it keeps working fine.

My question is, when is evaluated the <%# MyMethod(Eval("Test")) %> ?

Thanks,
Lubomir
 
Hi,

HeaderText does not have impact on the databinding expression what

<%# MyMethod(Eval("Test")) %>

effectively is.

Behind the scenes ASP.NET creates a databound literal control (at the place
of this expression in the control tree) which has handler for DataBinding
events and in that, it evaluates the expression (looks for given property in
the data source , to put it simply).

If you want to change the field for BoundField, you can do it by changing
DataField, but that impacts of course only the BoundField itself.
 
Back
Top