开发者

Simple Databinding Problem

I have a page, which has a public property of type myCustomWebProfile.

In code behind I have a textbox, and I am trying to bind the text box, to a property of my web profile described above.

No matter which variations of the binding syntax I use - the textbox is never populated开发者_如何学编程 when it's rendered.

Any help will be greatly appreciated.

Here is the C# code-behind class:

public partial class Profile : selfSvcPage
    {
        public WebProfile pgProfile { get; set; }

        protected void Page_Init(object sender, EventArgs e)
        {
            pgProfile = WebProfile.Current;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            object o = WebProfile.Current.FirstName;
            //Successfully populates with a string

            object b = DataBinder.Eval(pgProfile, "FirstName");
            //Successfully populates with a string
        }
    }

Here is the code markup:

<telerik:RadTextBox ID="FirstName" Text='<%# Eval("pgProfile.FirstName")     %>' SkinID="formText" CssClass="formField" runat="server"/>


Try this:

<telerik:RadTextBox ID="FirstName" Text='<%# pgProfile.FirstName %>' SkinID="formText" CssClass="formField" runat="server"/>

And this:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    DataBind();
}

In your situation you might want to bind at an earlier stage. Refer to this for details:

Why will <%= %> expressions as property values on a server-controls lead to a compile errors?

The important part: 'As the last thing i noticed... When i try with <%# %> + Control.DataBind(), then i get what i would expect. '


Can you just do this in your Page_Load:

FirstName.Text = pgProfile.Current.FirstName;

Make sure the initialization of your pgProfile happens before the code above.


What i got from your code is you have a

class Profile

in that class you have made a property of a class webProfile.

Now by using this property you are trying to assign value i think you can try some thing like this

Text='<%#(DataBinder.Eval(Container.DataItem, "pgProfile.Current.FirstName")).ToString()%>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜