locked
Display icon in webgrid in webmatrix RRS feed

  • Question

  • User1264955881 posted

    Hi all,

    Looking for an example where an icon is displayed in webgrid. I am trying to do 2 things one is to display a small icon based on a condition in a row for that particular record. My 2nd issue is based of the file uplaoded find the size(how to do this) then display an icon.

    Regards & Cheers,

    Srini.

    Friday, March 21, 2014 11:29 AM

Answers

  • User-735851359 posted

    Hello,

    I use the following to show an image based on a condition:

    columns: grid.Columns(
            grid.Column(format:
            @<text>
            @if(item.Show == false){
             <a href="~/Admin/GuestBook.cshtml?idShow=@item.gbID" title="Add" ><img src="image.gif" alt="Add" title="Add" /></a>
            }
            </text>
            ),

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 21, 2014 4:52 PM

All replies

  • User379720387 posted

    I had asked this same question a few months ago. This is what someone else suggested

    istimezone ? picture one : picture two

    <li class="list-group-item"><span class="badge">@(istimezone ?
                        Html.Raw("<img src=\"/Images/closed18.png\" alt=\"image\" />") :
                        Html.Raw("<img src=\"/Images/open18.png\" alt=\"image\" />")
                        )</span>timezone</li>

    Friday, March 21, 2014 12:11 PM
  • User-735851359 posted

    Hello,

    I use the following to show an image based on a condition:

    columns: grid.Columns(
            grid.Column(format:
            @<text>
            @if(item.Show == false){
             <a href="~/Admin/GuestBook.cshtml?idShow=@item.gbID" title="Add" ><img src="image.gif" alt="Add" title="Add" /></a>
            }
            </text>
            ),

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 21, 2014 4:52 PM
  • User1264955881 posted

    Great example and it worked, but the 2nd part of the question is how to know the size of the file which is being uploaded.

    Sunday, March 23, 2014 12:57 AM
  • User-735851359 posted

    Mark as answer if helped

    Sunday, March 23, 2014 3:26 AM
  • User1713851783 posted

    srini23

    how to know the size of the file which is being uploaded

    If filename is the virtual path on the Web server of your file (e.g. "~/Images/myfile.jpg"),

    @using System.IO;
    
    @{
        FileInfo f = new FileInfo(Server.MapPath(filename));
        var fLength = f.Length;
    }
    

     then fLength is the file size in bytes.

     

    Sunday, March 23, 2014 2:27 PM
  • User1264955881 posted

    The above worked, what would be if the file is in DB.

    Sunday, March 23, 2014 8:15 PM
  • User1713851783 posted

    Generally it's a good habit to store the file size together with the file contents into the same record; for an example look at the Photo Gallery template.

    Anyway, you can know the content size of a Sql Server binary field with the t-sql DATALENGTH function. The following query shows file names e dimensions of all files stores in the Photo table of PhotoGallery db (Photo Gallery template):

    SELECT FileTitle, DATALENGTH(FileContents) FROM Photos

    Monday, March 24, 2014 4:43 AM