Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview to display and download files.But when i click on the download button nothing happens..the gridview is:

XML
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
            BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
            CellPadding="4" PageIndex="5" PageSize="5"
        style="margin-left: 312px; margin-top: 20px;" HorizontalAlign="Justify"
        onselectedindexchanged="GridView2_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="File_Name" HeaderText="File Name"
                    SortExpression="File_Name" />
                <asp:BoundField DataField="Document_Number" HeaderText="Document Number"
                    SortExpression="Document_Number" />
                <asp:BoundField DataField="Upload_Date" HeaderText="Uploaded On"
                    SortExpression="UploadDate" />
                <asp:BoundField DataField="Upload_User" HeaderText="Uploaded BY"
                    SortExpression="Upload_User" />
                <asp:ButtonField ButtonType="Link" CommandName="Dwn" Text="Download"
                    HeaderText="Download Files"/>
            </Columns>
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
            <RowStyle BackColor="White" ForeColor="#003399" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <SortedAscendingCellStyle BackColor="#EDF6F6" />
            <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
            <SortedDescendingCellStyle BackColor="#D6DFDF" />
            <SortedDescendingHeaderStyle BackColor="#002876" />
        </asp:GridView>


and the rowcommad is

C#
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)

    {

       if (e.CommandName == "Dwn")
       {
           string path = ("NewFolder1") + "\\" +ddcollege.SelectedValue + "\\" + dddept.SelectedValue + "\\"
                         +ddcategory.SelectedValue + "\\" + ddloctn.SelectedItem + "\\";

            int index = Convert.ToInt32(e.CommandArgument);

           GridViewRow row = GridView2.Rows[index];

           string fName = row.Cells[1].Text;

           Response.ContentType = "application/octet-stream";

            Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);

          Response.TransmitFile(Server.MapPath(path+ fName));

            Response.End();


       }


    }


any idea as to y.I even tried to debug it but upon clicking the button..the lines are not reached.

Thanks
Posted
Comments
madhuri@mumbai 24-Aug-12 1:58am    
hi,
where is your on OnRowCommand of gridview,i think you should add it in <asp:gridview OnRowCommand="GridView2_RowCommand">

There is no row command specified for you grid you have to add this..

OnRowCommand="GridView2_RowCommand"
 
Share this answer
 
Yaa right Row Command is not specified in your gridview code & also you have not passed CommandArgument. Just like below

CommandName="Dwn" CommandArgument=value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900