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. DataGrid problem

DataGrid problem

Scheduled Pinned Locked Moved ASP.NET
questionhelp
12 Posts 6 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 the pink jedi

    one of the column in my datagrid is binded to some smallint numbers. However, i want every smallint 1 to show as the string "one" and 2 as the string "two" instead of the alpha numerical representation. how do i do that in codebehind programming? thanks very much

    M Offline
    M Offline
    M LN Rao
    wrote on last edited by
    #3

    private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { switch(@smallint) case 1: e.Item.Cells[0].Text = "One"; case 2: e.Item.Cells[0].Text = "Two"; case 2: . . . } Is that okay

    T 1 Reply Last reply
    0
    • T the pink jedi

      one of the column in my datagrid is binded to some smallint numbers. However, i want every smallint 1 to show as the string "one" and 2 as the string "two" instead of the alpha numerical representation. how do i do that in codebehind programming? thanks very much

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

      Create a public function to solve it. maybe just like this: public string ChangeNumber(string strNum) { switch (strNum) { case "1": return "one"; break; case "2": return "two"; break; ... } } maybe this method is so fool but it is a straight .... :( Study...

      T I 2 Replies Last reply
      0
      • M M LN Rao

        private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { switch(@smallint) case 1: e.Item.Cells[0].Text = "One"; case 2: e.Item.Cells[0].Text = "Two"; case 2: . . . } Is that okay

        T Offline
        T Offline
        the pink jedi
        wrote on last edited by
        #5

        Thanks for the help but that don't work

        1 Reply Last reply
        0
        • I ice hotty

          Create a public function to solve it. maybe just like this: public string ChangeNumber(string strNum) { switch (strNum) { case "1": return "one"; break; case "2": return "two"; break; ... } } maybe this method is so fool but it is a straight .... :( Study...

          T Offline
          T Offline
          the pink jedi
          wrote on last edited by
          #6

          how do i apply that to the datagrid?

          1 Reply Last reply
          0
          • I ice hotty

            Create a public function to solve it. maybe just like this: public string ChangeNumber(string strNum) { switch (strNum) { case "1": return "one"; break; case "2": return "two"; break; ... } } maybe this method is so fool but it is a straight .... :( Study...

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #7

            man thats ugly. Looks like VB code 1 line of code equals many bugs. So don't write any!!

            1 Reply Last reply
            0
            • T the pink jedi

              one of the column in my datagrid is binded to some smallint numbers. However, i want every smallint 1 to show as the string "one" and 2 as the string "two" instead of the alpha numerical representation. how do i do that in codebehind programming? thanks very much

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #8

              If theres a way to avoid it I would You can do an interpretation of the number but that would be difficult or tedious. whichever Define an enumeration public enum Number zero = 0, one, two, ... etc.. ... } Now to display the value Console.WriteLine("The answer is " + Enum.Parse(typeof(Number), "1", true)); Obviously you would need to define tens, hundreds, and so one. public enum tens { ten = 10, twenty = 20 } and then concatenate them together. Its very annoying, but if thats what you want it will work. Its ugly but it works. Nick 1 line of code equals many bugs. So don't write any!! -- modified at 9:17 Tuesday 24th January, 2006

              T 1 Reply Last reply
              0
              • I Ista

                If theres a way to avoid it I would You can do an interpretation of the number but that would be difficult or tedious. whichever Define an enumeration public enum Number zero = 0, one, two, ... etc.. ... } Now to display the value Console.WriteLine("The answer is " + Enum.Parse(typeof(Number), "1", true)); Obviously you would need to define tens, hundreds, and so one. public enum tens { ten = 10, twenty = 20 } and then concatenate them together. Its very annoying, but if thats what you want it will work. Its ugly but it works. Nick 1 line of code equals many bugs. So don't write any!! -- modified at 9:17 Tuesday 24th January, 2006

                T Offline
                T Offline
                the pink jedi
                wrote on last edited by
                #9

                actually, i just want to know how to alter the value of the datagrid cell from a int to a string. Any idea how i am able to do that?

                D I 2 Replies Last reply
                0
                • T the pink jedi

                  actually, i just want to know how to alter the value of the datagrid cell from a int to a string. Any idea how i am able to do that?

                  D Offline
                  D Offline
                  Daniel Santillanes
                  wrote on last edited by
                  #10

                  Are you using a template column for this in particular? If so, in the ItemDataBound event you can use some of the suggestions that other cpians have offered. daniero

                  T 1 Reply Last reply
                  0
                  • T the pink jedi

                    actually, i just want to know how to alter the value of the datagrid cell from a int to a string. Any idea how i am able to do that?

                    I Offline
                    I Offline
                    Ista
                    wrote on last edited by
                    #11

                    You need to change your data source. If this is a table, then change the column data type DataTable.Column["mycolumn"].DataType = typeof(string); Changing the data grid itself will not have a satisfactory desired effect. Change the underlying data source, that way your change maintains consistency. Nick 1 line of code equals many bugs. So don't write any!!

                    1 Reply Last reply
                    0
                    • D Daniel Santillanes

                      Are you using a template column for this in particular? If so, in the ItemDataBound event you can use some of the suggestions that other cpians have offered. daniero

                      T Offline
                      T Offline
                      the pink jedi
                      wrote on last edited by
                      #12

                      hey, Thanks for the help. That is what i need

                      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