dynamically set databind expression?

Posted on 2008-11-16
Last Modified: 2012-05-05
I have a GridView with a TemplateField
                                <asp:Label ID="lblDisplayItem" runat="server" Text='<%# Eval("Description") %>' />
                                <asp:TextBox ID="txtEditItem" runat="server" Text='<%# Eval("Description") %>' />

Is it possible to set the '<%# Eval("Description") %>' to another field at run time?

Any help appreciated, Thanks
Question by:colonel720
    LVL 2

    Accepted Solution

    try adding DataBinding event to this Label control, than in that event try this:

    private void lc_DataBinding(object sender, EventArgs e)
                var lc = (Label) sender;
                var container = (RepeaterItem)lc.NamingContainer;

                lc.Text = DataBinder.Eval(container.DataItem, "SOME NEW FIELD NAME");

    hope it helped...
    LVL 1

    Author Closing Comment

    Didn't get to test it, but I won't be taking this route after all. I am giving you the points for responding with something that  by the looks of it, works.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now