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. Gridview TemplateField

Gridview TemplateField

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdockerquestionannouncement
2 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.
  • B Offline
    B Offline
    Brendan Vogt
    wrote on last edited by
    #1

    Hi, I am using ASP.NET and C# 2.0. I have the following piece of code in my gridview control: [Insert / Update Items](UpdateOrderItems.aspx?OrderID=<%# DataBinder.Eval(Container.DataItem, "ID") %>) Currently the text of the link is Insert / Update Items. I want to do a test on this, if the order has been placed, then I want the link text to display "View", and if it has not been placed, the display "Insert / Update Items". I have now I idea where to do this test?? In my C# class behind the .aspx file? The reson being because the gridview populates the rows and coloumn for you. Please can someone advise. Regards, ma se

    J 1 Reply Last reply
    0
    • B Brendan Vogt

      Hi, I am using ASP.NET and C# 2.0. I have the following piece of code in my gridview control: [Insert / Update Items](UpdateOrderItems.aspx?OrderID=<%# DataBinder.Eval(Container.DataItem, "ID") %>) Currently the text of the link is Insert / Update Items. I want to do a test on this, if the order has been placed, then I want the link text to display "View", and if it has not been placed, the display "Insert / Update Items". I have now I idea where to do this test?? In my C# class behind the .aspx file? The reson being because the gridview populates the rows and coloumn for you. Please can someone advise. Regards, ma se

      J Offline
      J Offline
      John Petersen
      wrote on last edited by
      #2

      Hello ma se There are different ways of doing this. One way is to create a method in the code behind file that returns the value that you want to display. So you replace your "Insert / Update Items" part with a method call as the sample below. You can send any data to this method for it to be able to return the right value. Remember to make the method protected, otherwise you cant use it from the aspx page. [<%# GetUrlActionText( DataBinder.Eval(Container.DataItem, "ID") %>](UpdateOrderItems.aspx?OrderID=<%# DataBinder.Eval(Container.DataItem, "ID") %>) // Put in code behind file protected string GetUrlActionText(string id) { // Code to return either Insert / Update Items or View bool isOrdered = GetOrderIsPlaced(id); if (isOrdered) return "View"; else return "Insert / Update Items"; } Another way is to make the check in the aspx file. <% if (orderPlaced == true) { %> [View](UpdateOrderItems.aspx?OrderID=<%# DataBinder.Eval(Container.DataItem, "ID") %>) [Insert / Update Items](UpdateOrderItems.aspx?OrderID=<%# DataBinder.Eval(Container.DataItem, "ID") %>) <% } %> the orderPlaced variable is a protected variable in the code behind class that contains the state of the order. I hope this helps you out. Kind Regards, John Petersen

      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