문제

Let say that we have an object

class Entity
{
    public string ID {get; set;}
    public string Name {get; set;}
}

I want to bind properties to two textboxes on a page something like this:

<asp:FormView ID="FormView" runat="server">
  <ItemTemplate>
    <asp:textbox ID="TextId" Text='<%# Bind("ID") %>'/>
    <asp:textbox ID="TextId" Text='<%# Bind("Name") %>'/>
  </ItemTemplate>
</asp:FormView>

and then write this in code behind

public EntityObject
{
    get { return ViewState["Entity"] as Entity; }
    set { ViewState["Entity"] = value; }
}

protected override void OnInit(EventArgs e)
{
    if (EntityObject== null)
        EntityObject= new EntityObject();

    FormView.DataSource = new[] { EntityObject };
    FormView.DataBind();
    base.OnInit(e);
}

And when I enter values in textboxes I expect EntityObject to have these values in properties when page reloads after PostBack, but properties are always null.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top