Binding

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
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top