如何在gridview中触发链接按钮 [英] how to fire link button in gridview

查看:62
本文介绍了如何在gridview中触发链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 选择结果。无URL 

选择 2 C:\ Users \FABS \Documents\Xml Search \\\upload\count.xml
选择 3 C:\ Users \FABS \Documents\Xml Search\upload\Doc.xml







我的Gridview显示如下......然后在URL列中绑定为gridview中的链接按钮

....现在问题是当我在gridview表中单击此URL链接时如何打开或如何显示该文档....请帮助我????

解决方案

如何在ASP.NET中的gridview中添加超链接 [ ^ ]


如果要正常打开文件,可以使用响应.Redirect(YourFilePath)。如果您想下载该文件,那么您可以使用下面的功能。在GridView的RowCommand事件中调用该函数并传递相应文件的路径。试试这个:

 <! -    这应该存在于gridview itemtemplate内的aspx文件中   - >   
< span class =code-keyword>< asp:LinkBut​​ton ID = lnkView runat = server 文字 = < span class =code-keyword>查看文档 CommandName = 查看 CommandArgument =' <% #EVal( URL) %>' / >



  protected   void  Gridview_RowCommand( Object  sender,GridViewCommandEventArgs e)
{
if (e.CommandName == 查看
{
DownloadFile(e.CommandArgument.ToString());
}
}

public void DownloadFile( string FilePath)
{
Response.Clear();
Response.ContentType = @ application\octet-stream;
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(FilePath));
Response.AddHeader( Content-Disposition attachment; filename = + file.Name);
Response.AddHeader( Content-Length,file.Length.ToString()) ;
Response.ContentType = application / octet-stream;
Response.WriteFile(file.FullName);
Response.Flush();
}







希望它有所帮助!

- 阿米特


Select   Result.No                  URL 

Select     2   C:\Users\FABS\Documents\Xml Search\upload\count.xml
Select     3   C:\Users\FABS\Documents\Xml Search\upload\Doc.xml




My Gridview Showing like this ......then in URL column bind as link button in gridview
....Now problem is how to open or how to show that document when i click this URL link in gridview table....Pls help me????

解决方案

how to add Hyperlink in gridview in ASP.NET[^]


If you want to open the file normally then you can use Response.Redirect(YourFilePath). And if you want to download the file then you can use the function below. Call the function in your RowCommand Event of GridView and pass the path of corresponding file. Try this:

<!--This should be there in your aspx file inside gridview itemtemplate-->
<asp:LinkButton ID="lnkView" runat="server" Text="View Document" CommandName="View" CommandArgument='<%#EVal("URL")%>'/>


protected void Gridview_RowCommand(Object sender, GridViewCommandEventArgs e)
{
   if(e.CommandName == "View")
   {
       DownloadFile(e.CommandArgument.ToString());
   }
}

public void DownloadFile(string FilePath)
{
    Response.Clear();
    Response.ContentType = @"application\octet-stream";
    System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(FilePath));
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.Flush();
}




Hope it helps!
--Amit


这篇关于如何在gridview中触发链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆