在新视窗中开启Word档案或其他档案 [英] open word file or other file in new window

查看:92
本文介绍了在新视窗中开启Word档案或其他档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gridview行命令属性,但是当我单击查看命令"按钮时,我想在窗口中打开文件..

代码是:---

i am using the gridview row command property but i want to open file in window when i clicked on View command button..

code is: ---

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {

       if (e.CommandName.Equals("view"))
       {
           int index = System.Convert.ToInt32(e.CommandArgument);
           Label l1 = (Label)GridView1.Rows[index].FindControl("Label1");
            Response.Redirect(l1.Text);

      }
   }



在l1中,文档的路径已保存,但是当PDF文件是打开文件时却在同一窗口中打开,但是我想在新窗口中使用编码打开PDF文件或word,excel等...请帮助我...

谢谢
密特什

[edit]已添加代码块-OriginalGriff [/edit]



in l1 the path of document is save but it open in same window when PDF file is but i want to open PDF file or word,excel etc... in new window using coding... plz help me...

Thanksss
Mitesh

[edit]Code block added - OriginalGriff[/edit]

推荐答案

使用window.open().
GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//find control here
control cnt = (control)e.Row.Cells[index].FindControl("view");//do proper control typecast
Label l1 = (Label)e.Row.Cells[index].FindControl("Label1");
cnt.Attributes.Add("onclick", "Javascript:window.open('"+l1.text+"', '', '');");
}



[edit]添加了标签-Nelek [/edit]



[edit] added tags - Nelek [/edit]


这篇关于在新视窗中开启Word档案或其他档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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