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 to show file size in kb in dataGrid

How to show file size in kb in dataGrid

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
4 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.
  • H Offline
    H Offline
    hemant kaushal
    wrote on last edited by
    #1

    In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this

    J K 2 Replies Last reply
    0
    • H hemant kaushal

      In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this

      J Offline
      J Offline
      Jupiter9
      wrote on last edited by
      #2

      There are 1024 bytes in a KB. int kb = (int)(size/1024);

      1 Reply Last reply
      0
      • H hemant kaushal

        In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this

        K Offline
        K Offline
        King_kLAx
        wrote on last edited by
        #3

        Use a code behind method like this one - protected string FormatBytes(double bytes) { double gigabyte = 1024 * 1024 * 1024; double megabyte = 1024 * 1024; double kilobyte = 1024; if (bytes > gigabyte) { return string.Format("{0:#,###,###.00} GB", (bytes / gigabyte)); } else if (bytes > megabyte) { return string.Format("{0:#,###.00} MB", (bytes / megabyte)); } else if (bytes > kilobyte) { return string.Format("{0:#,###.00} KB", (bytes / kilobyte)); } else { return string.Format("{0:#,###} B", bytes); } } Then on your column item template use somthing like this - This should do the trick! Kind Regards Ian Claxton C# is for life not just for christmas

        H 1 Reply Last reply
        0
        • K King_kLAx

          Use a code behind method like this one - protected string FormatBytes(double bytes) { double gigabyte = 1024 * 1024 * 1024; double megabyte = 1024 * 1024; double kilobyte = 1024; if (bytes > gigabyte) { return string.Format("{0:#,###,###.00} GB", (bytes / gigabyte)); } else if (bytes > megabyte) { return string.Format("{0:#,###.00} MB", (bytes / megabyte)); } else if (bytes > kilobyte) { return string.Format("{0:#,###.00} KB", (bytes / kilobyte)); } else { return string.Format("{0:#,###} B", bytes); } } Then on your column item template use somthing like this - This should do the trick! Kind Regards Ian Claxton C# is for life not just for christmas

          H Offline
          H Offline
          hemant kaushal
          wrote on last edited by
          #4

          Thanks it's work :)

          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