我的HyperLink控件在datagrid的模板中,怎样才能下载所选的文件?

解决方案 »

  1.   

    把它的URL設為文件路徑及文件名就可以
      

  2.   

    Clicked(...)
    {Response.Redirect("http://localhost/myweb/myapp.exe");}
      

  3.   

    public void DownFile(string filename,string OldName)
    {
    System.IO.FileInfo file = new System.IO.FileInfo(filename); Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + OldName);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.End();
    }
      

  4.   

    我是使用模块列的
    <asp:ButtonColumn Text="下载" HeaderText="下载" CommandName="DownLoad"></asp:ButtonColumn>
    private void ctlList_ItemCommand(object source, DataGridCommandEventArgs e)
    {
    if(e.CommandName=="DownLoad")
    {
    TableCell itemCell = e.Item.Cells[0]; string strFile=Server.MapPath(itemCell.Text);
    TableCell itemCell2 = e.Item.Cells[2];
    DownFile(strFile,itemCell2.Text);
    }
    if(e.CommandName=="Delete")
    {
    ........... }
      

  5.   

    试用模版列,最好在datagrid绑定的时候就给hyperlink添加连接了
    ItemDataBound(....)
    {
        HyperLink hl=e.Item.FinControl("..");
        hl.Text="...";
        hl.NavagatUrl="...";
        ....
        
    }