Please help me,
i dont know what is wrong with this code
it return with error:
No overload for 'GridView1_SelectedIndexChange' matches delegate 'System.EventHandler'
downlaod.aspx:
<%@ Page Language="C#" MasterPageFile="~/msportal.master" AutoEventWireup="true" CodeFile="Download.aspx.cs" Inherits="Download" Title="Download Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=lemaridata;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [uplod]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
AllowPaging="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" Caption="Uploaded Media" CaptionAlign="Top" CellPadding="4"
DataKeyNames="ID" ForeColor="Black" GridLines="Horizontal"
PageSize="5" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="FileName" HeaderText="FileName"
SortExpression="FileName" />
<asp:BoundField DataField="Extension" HeaderText="Extension"
SortExpression="Extension" />
<asp:ButtonField ButtonType="Button" CommandName="Select" Text="Download"
HeaderText="Option" ShowHeader="True" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</asp:Content>
and the
download.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Download : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
{
try
{
SqlConnection con = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Initial Catalog=lemaridata;Integrated Security=True");
con.Open();
String ID = (GridView1.DataKeys[e.NewSelectedIndex].Value).ToString();
String qry = "Select * From uplod Where(ID=" + ID + ")";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string filename = (String)reader.GetValue(1);
byte[] fileToDownload = (byte[])reader.GetValue(2);
String fileExtension = (String)reader.GetValue(3);
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.ContentType = fileExtension;
Response.AddHeader("Content-Length", fileToDownload.Length.ToString());
Response.BinaryWrite(fileToDownload);
Response.Flush();
Response.End();
}
catch (System.Exception exp)
{
Label1.Text = (exp.Message);
}
}
}
please help...