我用Gridview绑定一些文件的名字,希望点击文件名就可以下载该文件。文件的上传我已经实现,可是很难实现我说的上述下载功能。 <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="603px" DataKeyNames="SoftID" OnRowDeleting="GridView3_RowDeleting">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="SoftID" HeaderText="SoftID" Visible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="SoftID" DataNavigateUrlFormatString="Soft.aspx?SoftID={0}"
DataTextField="SoftName" HeaderText="软件标题">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:BoundField DataField="SoftContent" HeaderText="软件介绍">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="SoftID" DataNavigateUrlFormatString="Soft.aspx?SoftID={0}"
DataTextField="SoftLogin" HeaderText="下载" />
<asp:CommandField DeleteText="删除软件" HeaderText="删除软件" ShowDeleteButton="True" />
</Columns>
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
ForeColor="#333333" GridLines="None" Width="603px" DataKeyNames="SoftID" OnRowDeleting="GridView3_RowDeleting">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="SoftID" HeaderText="SoftID" Visible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="SoftID" DataNavigateUrlFormatString="Soft.aspx?SoftID={0}"
DataTextField="SoftName" HeaderText="软件标题">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:BoundField DataField="SoftContent" HeaderText="软件介绍">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="SoftID" DataNavigateUrlFormatString="Soft.aspx?SoftID={0}"
DataTextField="SoftLogin" HeaderText="下载" />
<asp:CommandField DeleteText="删除软件" HeaderText="删除软件" ShowDeleteButton="True" />
</Columns>
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
解决方案 »
- 请问各位,怎样才能在Session_End()中调用Session中的值?
- 请教怎么上传和下载图片,以及怎么上传和下载压缩文件。跪求高手
- 站点地图sitemap如何输入&符号
- 奇怪的问题,asp.net用了ajax技术遇到的,百思不解,特来请问
- 你们有用户控件(ascx控件)方面的学习资料,或示例吗?给一份,好吗?谢谢
- [ASP.NET入门随想七]主角与配角——OO思想的多态、接口与委托
- 关于页面的显示问题(在线等呀!!)??
- 鼠标到一个点上的问题
- 如果修改DataGrid翻页相关的属性?
- 请问如何用C#.net得到主板orCPU的序列号?
- 关于SQL2005存储过程转移的请教
- Discuz!NT怎么和现有的Asp.Net网站整合,实现单点登录
前台<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ID" ForeColor="#333333" GridLines="None"
onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="txt" HeaderText="内容" />
<asp:ButtonField CommandName="DownLoad" HeaderText="下载" Text="下载"
DataTextField="Files" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
后台
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = int.Parse(e.CommandArgument.ToString());
if (e.CommandName == "DownLoad")
{
string g = this.GridView1.DataKeys[index].Value .ToString();
if (g != "")
{
DataTable dt=Class1.GetTxtID(g);
DataRowView rv = dt.DefaultView[0];
Session["txt"] = rv["Files"].ToString();
if (Session["txt"] != null )
{
string path = Server.MapPath("File/") + Session["txt"].ToString();
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filement=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octed-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
}
}
else
{
Page.RegisterStartupScript("sb3", "<script>alert('请先选择需要下载的文件,谢谢!')</script>");
}
}
}