【问题标题】:Retrieving info from gridview using deletebutton in commandfield使用命令字段中的删除按钮从网格视图中检索信息
【发布时间】:2016-03-30 19:28:03
【问题描述】:

我有一个 gridview 正在运行。我有一个命令字段,可以从我的 SQL Server 中删除记录。在我的文件系统上,我有所有这些图像文件。

我找不到(或者我不知道如何专门搜索此内容)有关如何将文件名从记录本身存储到我后面代码中的字符串中的任何信息。

我想使用命令字段删除按钮,然后将“文件名”同时存储在一个字符串中。所以我可以运行一个存储过程,然后从我的文件系统中删除该文件。

知道如何将这些信息存储在字符串中吗?

提前致谢。

【问题讨论】:

  • 您叙述场景的方式有些混乱,您能否重新定义问题以便更好地理解。
  • 如果我按下删除按钮/命令字段,我会将“图像名”存储在我的代码隐藏的字符串中。

标签: c# gridview commandfield


【解决方案1】:

你可以这样做:

public String [] readFile(String filePath){
        String [] lines=new String[1000];//Enough lines.
        int counter=0;
        try{
            File file = new File(filePath);//The path of the File
            FileReader fileReader1 = new FileReader(file);
            BufferedReader buffer = new BufferedReader(fileReader1);
            boolean flag=true;
            while(true){
                try{
                    lines[counter]=buffer.readLine();//Store a line in the array.
                    if(lines[counter]==null){//If there isn't any more lines.
                        buffer.close();
                        fileReader1.close();
                        break;//Stop reading and close the readers.
                    }
                    counter++;
                }catch(Exception ex){
                    break;
                }
            }
        }catch(FileNotFoundException ex){
            System.out.println("File not found.");
        }catch(IOException ex){
            System.out.println("Exception ocurred.");
        }
        return lines;
    }

或者只是另一个例子;

List<string> s = new List<string>();
s.Add("c:\\documents and settings\\sound1.mp3");
s.Add("c:\\documents and settings\\sound2.mp3");

var mp3paths = s.Where(x => String.Compare(".mp3", Path.GetExtension(x), true) == 0);
var exepaths = s.Where(x => String.Compare(".exe", Path.GetExtension(x), true) == 0);

希望这会有所帮助。

【讨论】:

  • 对不起...这对我没有帮助。我只需要一个示例页面,因为我对此非常陌生。
猜你喜欢
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-31
  • 2017-09-29
  • 2010-10-26
  • 1970-01-01
相关资源
最近更新 更多