Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Bind ASP.NET to a property of a class

Bind ASP.NET to a property of a class

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netwpfsysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi folks! Maybe anyone can help me with this. I'm from WPF world and am used to bind to objects in other classes. I found many examples to bind to lists, but none how to bind to a property of another class. So here's the deal: Default.aspx.cs

    private DefaultVM vm;

    protected void Page_Load(object sender, EventArgs e)
    {
    this.vm = new DefaultVm();
    }

    DefaultVM.cs

    public int TestValue { get;set;}

    public void DefaultVM()
    {
    TestValue = 10;
    }

    Default.aspx

    <asp:Label runat="server" Text='<%# DataBinder.Eval(vm,"TestValue")%>'/>

    None of this works. Tried a few other things as well, but without result. What am I doing wrong?

    R 1 Reply Last reply
    0
    • E ezazazel

      Hi folks! Maybe anyone can help me with this. I'm from WPF world and am used to bind to objects in other classes. I found many examples to bind to lists, but none how to bind to a property of another class. So here's the deal: Default.aspx.cs

      private DefaultVM vm;

      protected void Page_Load(object sender, EventArgs e)
      {
      this.vm = new DefaultVm();
      }

      DefaultVM.cs

      public int TestValue { get;set;}

      public void DefaultVM()
      {
      TestValue = 10;
      }

      Default.aspx

      <asp:Label runat="server" Text='<%# DataBinder.Eval(vm,"TestValue")%>'/>

      None of this works. Tried a few other things as well, but without result. What am I doing wrong?

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Try this:

      then, in Default.aspx.cs (perhaps in OnLoad or wherever you deem appropriate)

      vm = new DefaultVM();
      lblTest.Text = vm.TestValue.ToString();

      Mod: Sorry, yes, just thought: that probably wasn't the answer you were looking for. Make private DefaultVM vm; to public DefaultVM vm; that should do it.

      Tychotics: take us back to the moon "Life, for ever dying to be born afresh, for ever young and eager, will presently stand upon this earth as upon a footstool, and stretch out its realm amidst the stars." H. G. Wells

      modified on Friday, February 26, 2010 6:05 AM

      E 1 Reply Last reply
      0
      • R R Giskard Reventlov

        Try this:

        then, in Default.aspx.cs (perhaps in OnLoad or wherever you deem appropriate)

        vm = new DefaultVM();
        lblTest.Text = vm.TestValue.ToString();

        Mod: Sorry, yes, just thought: that probably wasn't the answer you were looking for. Make private DefaultVM vm; to public DefaultVM vm; that should do it.

        Tychotics: take us back to the moon "Life, for ever dying to be born afresh, for ever young and eager, will presently stand upon this earth as upon a footstool, and stretch out its realm amidst the stars." H. G. Wells

        modified on Friday, February 26, 2010 6:05 AM

        E Offline
        E Offline
        ezazazel
        wrote on last edited by
        #3

        Thank you! That did it:

        '<%# DataBinder.Eval(DataItem.vm,"TestValue")%>'

        and defining

        public DefaultVM vm;

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups