Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在网格视图中设置文件大小_C#_Asp.net_Gridview - Fatal编程技术网

C# 在网格视图中设置文件大小

C# 在网格视图中设置文件大小,c#,asp.net,gridview,C#,Asp.net,Gridview,您好,我需要帮助设置网格视图中苍蝇的大小,这是第一组代码 protected string DisplaySize(long? size) { if (size == null) return string.Empty; else { if (size < 1024) { return string.Format("{0:#} bytes", size.Value); }

您好,我需要帮助设置网格视图中苍蝇的大小,这是第一组代码

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);
        }
    }
}  
受保护的字符串显示大小(长?大小)
{
如果(大小==null)
返回字符串。空;
其他的
{
如果(大小<1024)
{
返回string.Format(“{0:}字节”,size.Value);
}
其他的
{
返回String.Format(“{0:}KB”,size.Value/1024);
}
}
}  
当我尝试添加更多值时,它不起作用,我只得到空白值

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));
        }
    }
} 
受保护的字符串显示大小(长?大小)
{
如果(大小==null)
返回字符串。空;
其他的
{
如果(大小<1024)
{
返回string.Format(“{0:}字节”,size.Value);
}
否则,如果(尺寸<10240)
{
返回String.Format(“{0:#}KB”,(size.Value/1024));
}
否则,如果(尺寸<102400)
{
返回String.Format(“{0:#}MB”,(size.Value/1024/1024));
}
其他的
{
返回String.Format(“{0:#}GB”,(size.Value/1024/1024/1024));
}
}
} 
截图工作:

屏幕截图不工作:


您的部门技术没有多大意义,我不知道它是否能解决您的问题,但您可以试试

((size.Value / 1024) / 1024)
((((size.Value / 1024) / 1024)/ 1024))
试试这个:

           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));
            }
if(大小<1024)
{
返回string.Format(“{0:}字节”,size.Value);
}
否则,如果(尺寸<1048576)
{
返回String.Format(“{0:#}KB”,(size.Value/1024));
}
否则,如果(尺寸<1073741824)
{
返回String.Format(“{0:#}MB”,((size.Value/1024)/1024));
}
其他的
{
返回String.Format(“{0:#}GB”,((size.Value/1024)/1024)/1024));
}
@VJ':不客气:),我很高兴能帮助你。