ワードドキュメントをダウンロード

6563 ワード

ソース:http://www.cnblogs.com/damonlan/archive/2012/04/28/2473525.html
作者:天涯をさすらう
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string courseName = ((Label)GridView1.Rows[e.RowIndex].Cells[1].FindControl("Label1")).Text.ToString();// GridView     
        string time = ((Label)GridView1.Rows[e.RowIndex].Cells[2].FindControl("Label2")).Text.ToString();// GridView    
        string tempPath = BusyworkManage.Path + tm.ReturnTeacherID(Request.Cookies["StudentID"].Value.ToString()) +BusyworkManage.TopicPath + 
courseName + "/" + courseName + "_" + time + ".doc";//                   !~~。
        string path = Server.MapPath(tempPath);
        FileInfo fInfo = new FileInfo(path);
        string fname = fInfo.Name;
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fname));
        Response.AddHeader("Content-Length", fInfo.Length.ToString());
        Response.ContentType = "application/octet-stream";
        Response.WriteFile(fInfo.FullName);
        Response.Flush();
まず説明したいのは、gridviewコントロールにbuttonボタンを置くと、次のようになります。
"GridView1" runat="server" AutoGenerateColumns="False" Height="139px"
        Width="100%" OnRowDeleting="GridView1_RowDeleting" 
            onselectedindexchanged="GridView1_SelectedIndexChanged">
        
        。。。。。。    。。。。。
            "  " HeaderText="  ">
                "Center" />
            
            "Button" DeleteText="    " ShowDeleteButton="True">
                "Center" />
            
            "    " DataNavigateUrlFormatString="SubmitBusywork.aspx?course={0}&time={1}" DataNavigateUrlFields="    ,    ">
                "Center" />
            
        
    
 
Lanny蘭東才出所:http://www.cnblogs.com/damonlan Q Q:*********E_mail:[email protected]ドンゴン[email protected]
このブログは皆様のご閲覧と転載を歓迎しますが、著作者の同意なしにこの文を保留しなければなりません。また、文章のページの明確な位置に原文の接続を提供します。あなたが私があなたの著作権を侵害していることを発見したら、すぐに私に連絡してください。