---
title: "How to set file size in grid view"  
description: "How to set file size in grid view"  
author: "Anonymous User"  
published: 2014-11-20  
updated: 2014-11-20  
canonical: https://www.mindstick.com/forum/12663/how-to-set-file-size-in-grid-view  
category: "asp.net"  
tags: ["asp.net", "file", "gridview"]  
reading_time: 1 minute  

---

# How to set file size in grid view

I need help setting the [size](https://www.mindstick.com/forum/159799/how-can-you-manage-the-size-of-mdf-and-ldf-files) of flies in a [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid)-[view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view), this first set of [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) 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](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) more [values](https://www.mindstick.com/forum/327/sum-textbox-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));        }    }}
```

## Replies

### Reply by Sumit Kesarwani

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));            }
```


---

Original Source: https://www.mindstick.com/forum/12663/how-to-set-file-size-in-grid-view

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
