Home > DeveloperSection > Forums > How to set file size in grid view
john rob

Total Post:108

Points:756
Posted on    November-20-2014 10:36 PM

 ASP.Net ASP.Net  File  Gridview 
Ratings:


 1 Reply(s)
 610  View(s)
Rate this:

I need help setting the size of flies in a grid-view, this first set of code works

protected string DisplaySize(long? size)

{

    if (size == null)

        return string.Empty;

    else

    {

        if (size < 1024)

        {

            return string.Format("{0:#} bytes", size.Value);

        }

        else

        {

            return String.Format("{0:#} KB", size.Value / 1024);

        }

    }

When I try to add more values it dose not work I just get blank values

 

protected string DisplaySize(long? size)

{

    if (size == null)

        return string.Empty;

    else

    {

        if (size < 1024)

        {

            return string.Format("{0:#} bytes", size.Value);

        }

        else if(size < 10240)

        {

            return String.Format("{0:#} KB", (size.Value / 1024));

        }

        else if(size < 102400)

        {

            return String.Format("{0:#} MB", (size.Value / 1024 / 1024));

        }

        else

        {

            return String.Format("{0:#} GB", (size.Value / 1024 / 1024 / 1024));

        }

    }

}



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-20-2014 11:46 PM

Hi John,

Try the below code:

if (size < 1024)

            {

                return string.Format("{0:#} bytes", size.Value);

            }

            else if(size < 1048576)

            {

                return String.Format("{0:#} KB", (size.Value / 1024));

            }

            else if(size < 1073741824)

            {

                return String.Format("{0:#} MB", ((size.Value / 1024) / 1024));

            }

            else

            {

                return String.Format("{0:#} GB", (((size.Value / 1024) / 1024) / 1024));

            }


Don't want to miss updates? Please click the below button!

Follow MindStick