web页面中点击下载跳出保存、打开窗体

//事件    

filepath = Request.PhysicalApplicationPath + @"Up_Load/SaveFile";
    cFile(GridView1.Rows[e.RowIndex].Cells[2].Text.ToString());

 

//封装方法

    private void cFile( string carg)
    {
        FileLoad(this.CurrentDirectory, carg);
    }

 

 

 

    public void FileLoad(string filepath, string argStr)
    {
        string filename = Path.Combine(filepath, argStr);
        //设置返回类型
        System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";

        //对文件名做标准编码
        string Encodefilename = System.Web.HttpContext.Current.Server.UrlEncode(argStr);
        Encodefilename = Encodefilename.Replace('+', ' ');

        //下载文件提示
        System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + Encodefilename);

        System.Web.HttpContext.Current.Response.TransmitFile(filename);
        System.Web.HttpContext.Current.Response.End();

    }

 

  string filepath = "";
    string CurrentDirectory
    {
        get
        {
            string Vfilepath = this.ViewState["CurrentDirectory"] as string;
            if (string.IsNullOrEmpty(Vfilepath))
            {
                Vfilepath = this.filepath + @"/" + depart + @"/";
            }
            return Vfilepath;
        }
        set
        {
            this.ViewState["CurrentDirectory"] = value;
        }

    }

 

 

您可以通过以下步骤实现: 1. 在DataGridView控件的ContextMenuStrip属性添加一个右键菜单。 2. 在右键菜单添加一个菜单项,并设置其Click事件,如下所示: ``` private void menuItem_Click(object sender, EventArgs e) { // 获取选的行 DataGridViewRow selectedRow = dataGridView1.SelectedRows[0]; // 获取选行的数据 string data = selectedRow.Cells[0].Value.ToString(); // 跳转到新窗体 Form2 form2 = new Form2(data); form2.Show(); } ``` 3. 在菜单项的Click事件,获取选的行的数据,然后跳转到新的窗体。 完整代码示例: ``` private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // 在右键菜单添加一个菜单项 ContextMenuStrip menu = new ContextMenuStrip(); ToolStripMenuItem menuItem = new ToolStripMenuItem("跳转到新窗体"); menuItem.Click += new EventHandler(menuItem_Click); menu.Items.Add(menuItem); // 设置右键菜单 dataGridView1.ContextMenuStrip = menu; } } private void menuItem_Click(object sender, EventArgs e) { // 获取选的行 DataGridViewRow selectedRow = dataGridView1.SelectedRows[0]; // 获取选行的数据 string data = selectedRow.Cells[0].Value.ToString(); // 跳转到新窗体 Form2 form2 = new Form2(data); form2.Show(); } ``` 注意:在跳转到新窗体时,可以将选行的数据作为参数传递给新窗体。在新窗体,可以根据传递的数据进行相应的处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值