Git Product home page Git Product logo

how-to-download-files-from-a-specific-aspxgridviews-column-e5175's Introduction

Grid View for ASP.NET Web Forms - How to download files from a specific column

This example demonstrates how to create a templated column with buttons that are rendered as links with icons. When a user clicks a link, the corresponding file is downloaded.

Download a file from a column

Overview

Specify a column's DataItemTemplate property, add a button to the template, and set the button's RenderMode property to Link.

<dx:GridViewDataColumn Caption="Doc" VisibleIndex="5">
    <DataItemTemplate>
        <dx:ASPxButton ID="ASPxButton1" runat="server" OnInit="ASPxButton1_Init" 
            AutoPostBack="False" RenderMode="Link" Text="Download">
            <Image IconID="actions_download_16x16" />
        </dx:ASPxButton>
    </DataItemTemplate>
</dx:GridViewDataColumn>

Handle the button's server-side Init event. In the handler, access the button's template container and get the container's key value. Then handle the button's client-side Click event and pass the container's key value to the FileDownloadHandler.asxh handler. In the handler, get the file specified by the container's key value and send this file to the browser.

protected void ASPxButton1_Init(object sender, EventArgs e) {
    ASPxButton button = (ASPxButton)sender;
    GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)button.NamingContainer;

    if (FileExists(container.KeyValue)) {
        button.ClientSideEvents.Click = string.Format("function(s, e) {{ window.location = 'FileDownloadHandler.ashx?id={0}'; }}", container.KeyValue);
    }
    else {
        button.ClientEnabled = false;
    }
}

private bool FileExists(object key) {
    return !string.IsNullOrEmpty(Product.GetData().First(p => p.ProductID.Equals(key)).ImagePath);
}

Files to Review

Documentation

how-to-download-files-from-a-specific-aspxgridviews-column-e5175's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.