Binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?THVib21pcg==?=

    Binding

    Hi,

    I have a gridview with tepmlate and boundfield columns.

    Two of columns are defined as follow:
    <asp:BoundFie ld HeaderText="Tes t" ...../>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <%# MyMethod(Eval(" Test")) %>
    </ItemTemplate>
    </asp:TemplateFie ld>

    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
  • Teemu Keiski

    #2
    Re: Binding

    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.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP




    "Lubomir" <Lubomir@discus sions.microsoft .comwrote in message
    news:C33FBDB5-D7AD-4104-81A9-B49C6CE6304D@mi crosoft.com...
    Hi,
    >
    I have a gridview with tepmlate and boundfield columns.
    >
    Two of columns are defined as follow:
    <asp:BoundFie ld HeaderText="Tes t" ...../>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <%# MyMethod(Eval(" Test")) %>
    </ItemTemplate>
    </asp:TemplateFie ld>
    >
    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

    Comment

    Working...