Repeater删除记录功能实现

通过添加按钮。在<AlternatingItemTemplate></AlternatingItemTemplate>加入

<td class="List_td">

                                    <asp:LinkButton ID="LinkButton1" runat="server"  CommandName ='<%# Eval("SID") %>' OnCommand ="LinkButton1_Click">删除</asp:LinkButton>
                                    </td>

                                    <td class="List_td">
                                    <asp:LinkButton ID="LinkButton3" runat="server"  CommandName ='<%# Eval("SID") %>' OnCommand ="LinkButton2_Click">下载</asp:LinkButton>

                                    </td>

后台的代码:

 protected void LinkButton1_Click(object sender, CommandEventArgs e)
    {
       

        string satId = e.CommandName.ToString();
        ObsConnection con = DB.createConnection();
        ObsCommand cmd = new ObsCommand("delete from SPATIAL.SATSAVE where SID='" + satId + "'", con);
        con.Open();
        cmd.ExecuteNonQuery();

        ObsCommand cmd1 = new ObsCommand("update SPATIAL.SATSAVE set SID=SID-1 where SID>'" + satId + "'", con);
        cmd1.ExecuteNonQuery();
        this.BindToDataGrid();

    }

下载的代码是:

protected void LinkButton2_Click(object sender, CommandEventArgs e)
    {
        string satId = e.CommandName.ToString();
        int SId = Convert.ToInt32(satId);
        string filePath = DownLoadFile(ProdFile(SId));
 
    }
    public string ProdFile(int SId)
    {
        ObsConnection con = DB.createConnection();
        con.Open();
        String sqlText = "select * from SPATIAL.SATSAVE where SID=@SId";
        ObsCommand cmd = new ObsCommand(sqlText, con);
        cmd.Parameters.Add("@SId", ObsDbType.Integer).Value = SId;
        ObsDataAdapter sda = new ObsDataAdapter("select * from SPATIAL.SATSAVE where SID=" + SId, con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        string name = ds.Tables[0].Rows[0]["STITLE"].ToString();
        sda.Dispose();
        ObsDataReader dr = cmd.ExecuteReader();
        byte[] buffByte = null;
        if (dr.Read())
        {
            ObsTransaction mytran = con.BeginTransaction();
            Blob blob = dr.GetBlob("SCONTENT");
            buffByte = blob.GetBytes(blob.Length());
            mytran.Commit();
        }
        dr.Close();
        con.Close();
        FileStream fs;
        string filePath = Server.MapPath(".//sat文件夹") + "//" + name;
        FileInfo fi = new FileInfo(filePath);
        fs = fi.OpenWrite();
        fs.Write(buffByte, 0, buffByte.Length);
        fs.Close();
        return name;
    }
    private string DownLoadFile(string fileName)
    {
        string filePath = Server.MapPath(".//sat文件夹") + "//" + fileName;

        FileInfo file = new FileInfo(filePath);
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码
        Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); //解决中文文件名乱码   
        Response.AddHeader("Content-length", file.Length.ToString());
        Response.ContentType = "appliction/octet-stream";
        Response.WriteFile(file.FullName);
        group.Add(filePath);

        for (int i = 0; i < group.Count - 1; i++)
        {
            String[] ss = new string[100];
            group.CopyTo(ss);
            System.IO.File.Delete(@ss[i]);
            group.Remove(ss[i]);
        }
        //System.IO.File.Delete(filePath );
        Response.End();

        return filePath;

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值