protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
             string folderpath=读数据库数据目录;
            
             LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
             l.Attributes.Add("onclick", "javascript:Openfolder('" + folderpath + "')")
       //这行代码的javascript怎么写,或者有没有其他更好的方法来调用Openfolder 

        }       public void Openfolder(string folderpath)
        {
            Process myProcess = new Process();
            
            try
            {
                
                myProcess.StartInfo.FileName =folderpath ;                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
            }
            catch (Win32Exception e)
            {
                if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                {
                    Console.WriteLine(e.Message + ". Check the path.");
                }                else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    Console.WriteLine(e.Message + ". You do not have permission to print this file.");
                }
            }
        }

解决方案 »

  1.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         string folderpath=读数据库数据目录;
                
         LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
         l.CommandName = "OPEN";
         l.CommandArgument = folderpath;
    }// 再在command事件中处理
    protected void GridView1_Rowcommand(....)
    {
         switch(e.CommandName)
         {
              case "OPEN":
                 // 打开名为e.CommandArgument的目录
         }}
      

  2.   

    为了100分,标准代码来了
            protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                switch(e.CommandName.ToLower()){
                    case "openfloder";
                        // 这里写打开目录的代码,目录名为 e.CommandArgument.ToString()
                        break;
                }                    
            }        protected void GridView1_DataBound(object sender, EventArgs e)
            {
                string folderpath = 读数据库数据目录;            LinkButton l = (LinkButton)e.Row.FindControl("lnkbt");
                l.CommandName = "openfloder";
                l.CommandArgument = folderpath;
            }
      

  3.   

    标题是:如何GridView里LinkButton打开本地文件目录  
    调试后没有问题,但是速度很慢,有没有更好的代码能快速打开本地文件开目录的代码?
      

  4.   

    晕,标题截了一半,还有一个是打开本地目录,抱歉,没看清楚那估计没办法了,还有办法比你直接js:open快吗?
      

  5.   

    <dl class='code'><dt>C# code</dt><dd><pre>
    试用一下。
      

  6.   

     l.Attributes.Add("onclick", "javascript:Openfolder('" + folderpath + "')")
    这行代码如何完善呢?我觉得javascript:应该会快些