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. How can you replace a field containing a code with text in a DataGrid?

How can you replace a field containing a code with text in a DataGrid?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestioncsharp
5 Posts 3 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.
  • T Offline
    T Offline
    Tom Welch
    wrote on last edited by
    #1

    I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.

    A severed foot is the ultimate stocking stuffer. - Mitch Hedberg

    P I 2 Replies Last reply
    0
    • T Tom Welch

      I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.

      A severed foot is the ultimate stocking stuffer. - Mitch Hedberg

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You could handle the DataGrid.ItemDataBound event and do something to replace the code with text. However it would be easier to do this in your database query, joining your main table to a lookup table that contains the code descriptions and returning the description instead of the code.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      T 1 Reply Last reply
      0
      • T Tom Welch

        I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.

        A severed foot is the ultimate stocking stuffer. - Mitch Hedberg

        I Offline
        I Offline
        ice hotty
        wrote on last edited by
        #3

        the follow is my way to solve it. i can code a public method in the cs code.. public string getCompele(string strValue) { string strReturn = ""; switch (strValue) { case "A": strReturn = "Active"; break; case "B": strReturn = "Expired"; break; case "C": strReturn = "Locked"; break; case "D": strReturn = "Unknown"; break; } return strReturn; } in the aspx code, i can use the method to get what i want,like this. ]]>' style="width: 119px;" i don't sure if this way can help you.

        Study...

        T 1 Reply Last reply
        0
        • I ice hotty

          the follow is my way to solve it. i can code a public method in the cs code.. public string getCompele(string strValue) { string strReturn = ""; switch (strValue) { case "A": strReturn = "Active"; break; case "B": strReturn = "Expired"; break; case "C": strReturn = "Locked"; break; case "D": strReturn = "Unknown"; break; } return strReturn; } in the aspx code, i can use the method to get what i want,like this. ]]>' style="width: 119px;" i don't sure if this way can help you.

          Study...

          T Offline
          T Offline
          Tom Welch
          wrote on last edited by
          #4

          Thanks for the reply to this one. I went with the other solution posted, but this helped me understand the binding mechanism a lot better. Up until now we've done everything programmatically here. Thanks.

          A severed foot is the ultimate stocking stuffer. - Mitch Hedberg

          1 Reply Last reply
          0
          • P pmarfleet

            You could handle the DataGrid.ItemDataBound event and do something to replace the code with text. However it would be easier to do this in your database query, joining your main table to a lookup table that contains the code descriptions and returning the description instead of the code.

            Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

            T Offline
            T Offline
            Tom Welch
            wrote on last edited by
            #5

            Thanks. I wasn't going to create a master table for code values but in the end that seems best. That way I can keep the program logic smaller and it helps document the whole code system too.

            A severed foot is the ultimate stocking stuffer. - Mitch Hedberg

            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