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