62,047
社区成员
发帖
与我相关
我的任务
分享
8 <asp:GridView ID="GridView" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView_PageIndexChanging" PageSize="12" >
9 <Columns>
10 <asp:BoundField DataField="UserID" HeaderText="UserID" />
11 <asp:BoundField DataField="C_Name" HeaderText="中文名字" />
12 <asp:BoundField DataField="E_Name" HeaderText="英文名字" />
13 <asp:BoundField DataField="salary" HeaderText="薪水" DataFormatString="{0:C}" HtmlEncode ="False"/>
14 <asp:HyperLinkField DataNavigateUrlFields="C_Name" DataNavigateUrlFormatString="Demo28_Url.aspx?para={0}" DataTextField="C_Name"
15 HeaderText="点击打开新页面" />
16 <asp:HyperLinkField DataNavigateUrlFields="UserID" DataNavigateUrlFormatString="Demo28_Url.aspx?para={0}" DataTextField="C_Name"
17 HeaderText="传递不同的参数(UserID)" />
18 </Columns>
19 <RowStyle HorizontalAlign="Center" />
20 <PagerStyle HorizontalAlign="Right" />
21 </asp:GridView>
<asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkbtnDown" runat="server" CommandName="DownLoad"
Text='<%#Eval("文件名") %>' CommandArgument=<%#Eval("文件路径") %>></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DownLoad")
{
HttpContext.Current.Response.ContentType = "application/ms-download";
string strPath = HttpContext.Current.Server.MapPath("~/") + e.CommandArgument;
System.IO.FileInfo file = new System.IO.FileInfo(strPath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
}
<%@ WebHandler Language="C#" Class="download" %>
using System;
using System.Web;
public class download : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string url = HttpContext.Current.Server.UrlDecode(context.Request.QueryString["url"]);
downloadfile(url);
}
public bool IsReusable {
get {
return false;
}
}
public void downloadfile(string s_fileName)
{
HttpContext.Current.Response.ContentType = "application/ms-download";
string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName; //这里根据实际路径填写
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
}
<asp:HyperLinkField DataTextField="cTitle" HeaderText="标题" SortExpression="cTitle"
DataNavigateUrlFields="userial" DataNavigateUrlFormatString="~/Information/IM_ReceiveInfo.aspx?ID={0}" Target="_self">
<ControlStyle Width="300px" />
</asp:HyperLinkField>
protected void GridViewInformationList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{//标题
string cTitle = ((HyperLink)(e.Row.Cells[1].Controls[0])).Text;
((HyperLink)(e.Row.Cells[1].Controls[0])).Text = CommonBusinessService.SubStr(cTitle, 100);
((HyperLink)(e.Row.Cells[1].Controls[0])).ToolTip = cTitle;
<asp:BoundField DataField="FILEPATH" HeaderText="文件路径" DataFormatString="<a href='#'>{0}</a>">
<asp:BoundField DataField="FILEPATH" HeaderText="文件路径" DataFormatString="<a href='#'>{0}</a>">