首页 新闻 会员 周边 捐助

asp.net 谁能帮我看看

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-02-16 09:42

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DownFiles.aspx.cs" Inherits="通告上传和下载.DownFiles" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
.postCon a,.postBody a,.feedbackCon a{text-decoration:underline;color:#0066cc;}
a{text-decoration:none;color:#000;}
*{margin:0;padding:0;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td>
                    通告信息浏览:</td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="GridView1" runat="server"
                     AllowPaging ="true"  AllowSorting ="true"
                     AutoGenerateColumns ="false"  Font-Size ="9pt" Width="457px"
                     onselectedindexchanged="GridView1_SelectedIndexChanged"
                      OnRowDataBound="GridView1_RowDataBound"
                       OnRowDeleted="GridView1_ RowDeleting" >
                    <Columns >
                    <asp:BoundField DataField ="id"  HeaderText ="编号" />
                    <asp:BoundField DataField ="title" HeaderText ="标题" />
                    <asp:BoundField DataField ="author" HeaderText ="发布人" />
                    <asp:BoundField DataField ="dates" HeaderText ="发布日期" />
                    <asp:CommandField HeaderText ="下载附件" ShowCancelButton ="false" ShowSelectButton ="true"
                     SelectText ="下载" ShowHeader ="true" >
                     <ControlStyle ForeColor ="Blue" />
                     </asp:CommandField >
                   

                    </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace 通告上传和下载
{
    public partial class DownFiles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
        {
            try
            {
                //获取编号信息
                string strid = GridView1.Rows[e.NewSelectedIndex ].Cells[0].Text;
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["tg"].ConnectionString);
                con.Open();
                string strpath = "";
                string strselect = "";
                strselect = "select * from tonggao where id='" + strid + "'";
                SqlDataAdapter da = new SqlDataAdapter(strselect, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strpath = ds.Tables[0].Rows[0][5].ToString();
                }
                con.Close();
                //下载操作

                string fullpathURL = Server.MapPath(strpath);
                System.IO.FileInfo file = new System.IO.FileInfo(fullpathURL);
                if (file.Exists)
                {
                    Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name));
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/application/octet-stream";
                    Response.WriteFile(file.FullName);     //使用Response对象保存文件 
                    Response.End();                         //结束Response对象 
                    Response.Flush();                       //刷新Response对象 
                    Response.Clear();                      //清空Response对象
                }
                else
                {
                    this.Page.RegisterStartupScript("ss", "<script>alert('文件不存在!')</script>");
                }
            }
            catch
            {
                this.Page.RegisterStartupScript("ss", "<script>alert('文件不存在!')</script>"); 
            }
        }
    }
}

////////////////////////////////////////////////////////////////////////////

运行后出现的问题

 

Server Error in '/' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1026: ) expected

Source Error:

 
Line 27:             <tr>Line 28:                 <td>Line 29:                     <asp:GridView ID="GridView1" runat="server"  Line 30:                     AutoGenerateColumns ="false"  Font-Size ="9pt" Width="457px" Line 31:                     onselectedindexchanged="GridView1_SelectedIndexChanged"


Source File: d:\DotNetWorkspace\文件上传和下载功能\通告上传和下载\DownFiles.aspx    Line: 29






Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

l277978707的主页 l277978707 | 初学一级 | 园豆:160
提问于:2012-02-02 16:53
< >
分享
所有回答(3)
0

就是少了一个右括号嘛,最好发文件上来看。

today4king | 园豆:3499 (老鸟四级) | 2012-02-02 17:55

么有少 ,如果把   Gridview里面的这些去掉

                      OnRowDataBound="GridView1_RowDataBound"
                       OnRowDeleted="GridView1_ RowDeleting"

 然后把 protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
        {

改为  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

运行是么有错了但是

调用不了这个

string strid = GridView1.Rows[e.NewSelectedIndex ].Cells[0].Text;

支持(0) 反对(0) l277978707 | 园豆:160 (初学一级) | 2012-02-03 14:17
0

哥呀您看 OnRowDeleted="GridView1_ RowDeleting" 的  GridView1_ RowDeleting中间多了个空格,还有   protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)     貌似GridViewSelectEventArgs 这个参数类型不对应该是EventArgs

陈齐 | 园豆:311 (菜鸟二级) | 2012-02-02 18:16

如果对应的参数是EventArgs这个的话,那就不能调用这个string strid = GridView1.Rows[e.NewSelectedIndex ].Cells[0].Text;

支持(0) 反对(0) l277978707 | 园豆:160 (初学一级) | 2012-02-03 14:11

@l277978707: 强转一下试试 GridView1.Rows[(e as GridViewSelectEventArgs ).NewSelectedIndex ].Cells[0].Text;

 

支持(0) 反对(0) 陈齐 | 园豆:311 (菜鸟二级) | 2012-02-03 23:37
0

强悍的楼主,我来接豆

LT | 园豆:97 (初学一级) | 2012-02-02 21:24

呵呵。。。

支持(0) 反对(0) l277978707 | 园豆:160 (初学一级) | 2012-02-03 14:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册