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. DataBinding logic

DataBinding logic

Scheduled Pinned Locked Moved ASP.NET
dockerhelp
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.
  • O Offline
    O Offline
    OmegaSupreme
    wrote on last edited by
    #1

    Is it possible to include some logic betweeb <%%> tags when databinding. What I want is something like the following :

    string m =
    DataBinder.Eval(Container.DataItem, "modelName").ToString();
    if ( m.Length > 20 ) Response.Write(m.Substring(0,20) + "..");
    else Response.Write(m);

    But I get the following error :

    Compiler Error Message: CS0103: The name 'Container' does not exist in the current context

    TIA. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon

    H 1 Reply Last reply
    0
    • O OmegaSupreme

      Is it possible to include some logic betweeb <%%> tags when databinding. What I want is something like the following :

      string m =
      DataBinder.Eval(Container.DataItem, "modelName").ToString();
      if ( m.Length > 20 ) Response.Write(m.Substring(0,20) + "..");
      else Response.Write(m);

      But I get the following error :

      Compiler Error Message: CS0103: The name 'Container' does not exist in the current context

      TIA. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon

      H Offline
      H Offline
      HiltonG
      wrote on last edited by
      #2

      Create a public function in your code-behind file and then call it as follows (the following is an example from within a datagrid TemplateColumn): <%# MyFunction(Container.DataItem("BlahField")) %> Find my .Net blog at http://hiltong.blogspot.com

      O 1 Reply Last reply
      0
      • H HiltonG

        Create a public function in your code-behind file and then call it as follows (the following is an example from within a datagrid TemplateColumn): <%# MyFunction(Container.DataItem("BlahField")) %> Find my .Net blog at http://hiltong.blogspot.com

        O Offline
        O Offline
        OmegaSupreme
        wrote on last edited by
        #3

        Hi Hilton, I did know that and thats what I've been doing but I've had this nagging feeling that there was a cooler way all the gurus where using and I wasn't in on it. But that'll do me, cheers. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon

        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