private void bindData() //绑定数据 { string sqlselect = "select AFI_ID,AFI_TSDEP,AFI_PJNAME,AFI_ENGNAME,AFI_PARTNAME,AFI_PARTNATURE,AFI_TUHAO,AFI_QUANTITY,AFI_CNTLTXT,AFI_DATACLCT,AFI_DATE,convert(CHAR,AFI_RQSTCDATE,102) AS AFI_RQSTCDATE,AFI_SUPPLERNM,AFI_ISPCTSITE,AFI_CONTACT,AFI_CONTEL,AFI_MANNM,AFI_NOTE,AFI_QCMANNM,AFI_SUBITEM from TBQM_APLYFORINSPCT where AFI_ID='" + AFI_ID + "'"; DataSet ds = DBCallCommon.FillDataSet(sqlselect); if (ds.Tables[0].Rows.Count > 0) { string contactName = ds.Tables[0].Rows[0]["AFI_CONTACT"].ToString(); string contactTel = ds.Tables[0].Rows[0]["AFI_CONTEL"].ToString(); lbid.Text = ds.Tables[0].Rows[0]["AFI_ID"].ToString();//报检编号 lbdep.Text = ds.Tables[0].Rows[0]["AFI_TSDEP"].ToString(); lbpjname.Text = ds.Tables[0].Rows[0]["AFI_PJNAME"].ToString(); lbengname.Text = ds.Tables[0].Rows[0]["AFI_ENGNAME"].ToString(); lbpartname.Text = ds.Tables[0].Rows[0]["AFI_PARTNAME"].ToString(); lbpartnature.Text = ds.Tables[0].Rows[0]["AFI_PARTNATURE"].ToString(); lbtuhao.Text = ds.Tables[0].Rows[0]["AFI_TUHAO"].ToString(); lbquantity.Text = ds.Tables[0].Rows[0]["AFI_QUANTITY"].ToString(); lbcontroltxt.Text = ds.Tables[0].Rows[0]["AFI_CNTLTXT"].ToString(); lbdataclct.Text = ds.Tables[0].Rows[0]["AFI_DATACLCT"].ToString(); lbpjdate.Text = ds.Tables[0].Rows[0]["AFI_DATE"].ToString(); lbrqstcdate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["AFI_RQSTCDATE"]).ToString("yyyy-MM-dd"); lbsupplyname.Text = ds.Tables[0].Rows[0]["AFI_SUPPLERNM"].ToString(); //供应商名称---需要确定 lbsite.Text = ds.Tables[0].Rows[0]["AFI_ISPCTSITE"].ToString(); lbcontact.Text = contactName; //联系人 lbtel.Text = contactTel; //联系人电话 //Label16.Text = ds.Tables[0].Rows[0]["AFI_CONTEL"].ToString();//联系电话 lbmannm.Text = ds.Tables[0].Rows[0]["AFI_MANNM"].ToString(); //根据Session值获取姓名 lbmeno.Text = ds.Tables[0].Rows[0]["AFI_NOTE"].ToString(); lbqcmn.Text = ds.Tables[0].Rows[0]["AFI_QCMANNM"].ToString(); hfditem.Value = ds.Tables[0].Rows[0]["AFI_SUBITEM"].ToString(); } bindzhijiandan(); bindItem(); }
private void bindData() //绑定数据 { string sqlselect1 = "select * from TBMP_PRDCTTASKDETAIL where PT_CODE='" + PT_CODE + "'"; DataSet ds1 = DBCallCommon.FillDataSet(sqlselect1); if (ds1.Tables[0].Rows.Count > 0) { Label1.Text = ds1.Tables[0].Rows[0]["PT_CODE"].ToString(); //生产任务编号 Label2.Text = ds1.Tables[0].Rows[0]["PT_ENGCONTEXT"].ToString(); //工程内容 Label3.Text = ds1.Tables[0].Rows[0]["PT_QUANTITY"].ToString(); //数量 Label4.Text = ds1.Tables[0].Rows[0]["PT_ENGNUM"].ToString(); // 工程量 Label5.Text = ds1.Tables[0].Rows[0]["PT_DLVRYDATE"].ToString(); //交货日期 Label6.Text = ds1.Tables[0].Rows[0]["PT_DRAWINGDATE"].ToString(); //图纸交付时间 Label7.Text = ds1.Tables[0].Rows[0]["PT_COST"].ToString(); //成本 Label8.Text = ds1.Tables[0].Rows[0]["PT_STATE"].ToString(); //状态 Label9.Text = ds1.Tables[0].Rows[0]["PT_NOTE"].ToString(); //备注 } string sqlselect2 = "select * from TBMP_PRDCTTASKTOTAL where PT_CODE='" + PT_CODE + "'"; DataSet ds2 = DBCallCommon.FillDataSet(sqlselect2); if (ds2.Tables[0].Rows.Count > 0) { //生产任务编号 tbproject.Text = ds2.Tables[0].Rows[0]["PT_PJNAME"].ToString(); //项目 tbeng.Text = ds2.Tables[0].Rows[0]["PT_ENGNAME"].ToString(); //工程 Label10.Text = ds2.Tables[0].Rows[0]["PT_PMCHARGERNM"].ToString(); //项目管理部负责人 Label11.Text = ds2.Tables[0].Rows[0]["PT_BPCHARGERNM"].ToString(); //经营策划部负责人 Label12.Text = ds2.Tables[0].Rows[0]["PT_PDCHARGERNM"].ToString(); //生产单位负责人 Label13.Text = ds2.Tables[0].Rows[0]["PT_ICKCOMNM"].ToString(); //收入核算单位 Label14.Text = ds2.Tables[0].Rows[0]["PT_PMEXECUTENM"].ToString(); //项目管理部经办人 Label15.Text = ds2.Tables[0].Rows[0]["PT_BPEXECUTENM"].ToString(); //经营策划部经办人 Label16.Text = ds2.Tables[0].Rows[0]["PT_PDEXECUTENM"].ToString(); //生产单位经办人 Label17.Text = ds2.Tables[0].Rows[0]["PT_TNCHARGERNM"].ToString(); //技术负责人 } }
protected void imgbtnDF_Click(object sender, ImageClickEventArgs e) { ImageButton imgbtn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)imgbtn.Parent.Parent; GridView gv = (GridView)imgbtn.Parent.Parent.Parent.Parent; string sqlStr = "select fileload,fileName,showName from " + ((ImageButton)sender).ID + " where fileID='" + gv.DataKeys[gvr.RowIndex].Value.ToString() + "'"; DataSet ds = DBCallCommon.FillDataSet(sqlStr); string strFilePath = ds.Tables[0].Rows[0]["fileload"].ToString() + @"\" + ds.Tables[0].Rows[0]["fileName"].ToString(); if (File.Exists(strFilePath)) { string showName = ds.Tables[0].Rows[0]["showName"].ToString(); System.IO.FileInfo file = new System.IO.FileInfo(strFilePath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(showName)); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.WriteFile(file.FullName); Response.Flush(); Response.End(); } else { filesError.Visible = true; filesError.Text = "文件已被删除,请通知相关人员上传文件!"; } }
protected void ib_Click(object sender, ImageClickEventArgs e) { //Response.Write("zhixing"); //获取imgbtnDelete的ImageButton对象 ImageButton imgbtn = (ImageButton)sender; string sqlStr = "select RP_SAVEURL,RP_FILENAME from TBQM_RPFILES where RP_ID='" + imgbtn.ValidationGroup + "'"; //打开数据库 Response.Write(sqlStr); DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取文件路径 string strFilePath = ds.Tables[0].Rows[0]["RP_SAVEURL"].ToString() + @"\" + ds.Tables[0].Rows[0]["RP_FILENAME"].ToString(); //Response.Write(strFilePath); if (File.Exists(strFilePath)) { System.IO.FileInfo file = new System.IO.FileInfo(strFilePath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name)); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.WriteFile(file.FullName); Response.Flush(); Response.End(); } else { filesError.Visible = true; filesError.Text = "文件已被删除,请通知相关人员上传文件!"; } }
protected void lbtnonload1_OnClick(object sender, EventArgs e) { string fileid = ((LinkButton)sender).CommandArgument.ToString(); string sqlStr = "select FILE_LOAD,FILE_NAME,FILE_SHOWNAME from CM_FILES where FILE_ID='" + fileid + "'"; //打开数据库 //Response.Write(sqlStr); DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取文件路径 string strFilePath = ds.Tables[0].Rows[0]["FILE_LOAD"].ToString() + @"\" + ds.Tables[0].Rows[0]["FILE_NAME"].ToString(); //Response.Write(strFilePath); if (File.Exists(strFilePath)) { System.IO.FileInfo file = new System.IO.FileInfo(strFilePath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["FILE_NAME"].ToString())); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.WriteFile(file.FullName); Response.Flush(); Response.End(); } else { filesError1.Visible = true; filesError1.Text = "文件已被删除,请通知相关人员上传文件!"; } }
protected void GridView1_DataBound() { foreach (GridViewRow gr in GridView1.Rows) { //HtmlTable table = (HtmlTable)gr.FindControl("table1"); //HtmlTableRow tr = new HtmlTableRow(); System.Web.UI.WebControls.Label lb = (System.Web.UI.WebControls.Label)gr.FindControl("lb_report"); string sql = "select * from TBQM_RPFILES where PR_CONTENT='" + lb.Text.Trim() + "'order by RP_UPLOADDATE "; DataSet ds = DBCallCommon.FillDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //HtmlTableCell td = new HtmlTableCell(); //td.InnerHtml = "<a target='_self' href=" + Server.MapPath("zhijianbaobiao") + @"\" + ds.Tables[0].Rows[0]["RP_FILENAME"].ToString() + ">" + "查看" + "</a>"; //tr.Cells.Add(td); ImageButton ib = new ImageButton(); ib.Height = 18; ib.Width = 18; lb.Parent.Controls.Add(ib); ib.ImageUrl = "~/Assets/images/pdf.jpg"; ib.ToolTip = ds.Tables[0].Rows[i]["RP_FILENAME"].ToString(); ib.ValidationGroup = ds.Tables[0].Rows[i]["RP_ID"].ToString(); ib.Click += new ImageClickEventHandler(ib_Click);//注册事件 this.RegisterRequiresPostBack(ib); } } //table.Rows.Add(tr); } }
void GVBind() { string sql = "select * from tb_files where BC_CONTEXT='" + content + "'"; DataSet ds = DBCallCommon.FillDataSet(sql); ViewGridViewFiles.DataSource = ds.Tables[0]; ViewGridViewFiles.DataBind(); ViewGridViewFiles.DataKeyNames = new string[] { "fileID" }; }
private void bindGrid() { string sqlText = "select * from TBQC_FILEUPLOAD "; sqlText += " where UF_CODE='" + _uf_code + "' and UF_TYPE=" + _uf_type + ""; GridView1.DataSource = DBCallCommon.FillDataSet(sqlText); GridView1.DataBind(); Lbl_remind.Visible = false; }
private void bindGrid() { string sqlText = "select * from TBPM_ATTACHMENTS "; sqlText += " where AT_HTBH='" + _at_htbh + "' and AT_TYPE=" + _at_type + " and AT_SPLB=" + _at_sp + ""; GridView1.DataSource = DBCallCommon.FillDataSet(sqlText); GridView1.DataBind(); Lbl_remind.Visible = false; }
protected void GVBind(GridView gv, string table, string context) { string sql = "select * from " + table + " where BC_CONTEXT='" + context + "'"; DataSet ds = DBCallCommon.FillDataSet(sql); gv.DataSource = ds.Tables[0]; gv.DataBind(); gv.DataKeyNames = new string[] { "fileID" }; }
//初始化 private void GVBind() { string sql = "select * from OM_YONGYIN_Attach where OM_YY_CODE='" + lblCode.Text + "' "; DataSet ds = DBCallCommon.FillDataSet(sql); gvfileslist.DataSource = ds.Tables[0]; gvfileslist.DataBind(); gvfileslist.DataKeyNames = new string[] { "ID" }; }
void GVBind(GridView gv) { string sql = "select * from tb_files where BC_CONTEXT='" + HiddenFieldContent.Value + "' and fileload like '%ZCZJ_DPF%'"; DataSet ds = DBCallCommon.FillDataSet(sql); gv.DataSource = ds.Tables[0]; gv.DataBind(); gv.DataKeyNames = new string[] { "fileID" }; }
private void GVBind(string content) { string sql = "select * from TBQM_RPFILES where PR_CONTENT='" + content + "'"; DataSet ds = DBCallCommon.FillDataSet(sql); gvfileslist.DataSource = ds.Tables[0]; gvfileslist.DataBind(); gvfileslist.DataKeyNames = new string[] { "RP_ID" }; }
//数据库中删除 protected void DeleteFile(string sqlStr) { //打开数据库 DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取指定文件的路径 string strFilePath = ds.Tables[0].Rows[0]["SAVEURL"].ToString() + @"\" + ds.Tables[0].Rows[0]["FILENAME"].ToString(); //调用File类的Delete方法,停用指定文件 File.Delete(strFilePath);//文件不存在也不会引发异常 }
private void getContractInfo() { string sql = "select BC_CONTEXT from TBBS_CONREVIEW where BC_ID='" + id + "' ";//由BC_ID来获取合同文本的值 DataSet ds = DBCallCommon.FillDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { content = ds.Tables[0].Rows[0][0].ToString(); } }
protected void DeleteTFN(string sqlStr) { //打开数据库 DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取指定文件的路径 string strFilePath = ds.Tables[0].Rows[0]["fileload"].ToString() + @"\" + ds.Tables[0].Rows[0]["fileName"].ToString(); //调用File类的Delete方法,删除指定文件 File.Delete(strFilePath);//文件不存在也不会引发异常 }
//删除没有加限制条件 protected void btn_del_Click(object sender, EventArgs e) { List <string> lt = new List <string>(); List <string> ltsql = new List <string>(); for (int i = 0; i < Repeater1.Items.Count; i++) { CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("CKBOX_SELECT"); if (cb.Checked) { string code = ((Label)Repeater1.Items[i].FindControl("PT_CODE")).Text; lt.Add(code); } } foreach (string code in lt) { string selsql = "select PT_FILE,PT_FILE1 from TBMP_PRDCTTASKTOTAL where PT_CODE='" + code + "'"; DataSet ds = DBCallCommon.FillDataSet(selsql); if (ds.Tables[0].Rows.Count > 0) { string content = ds.Tables[0].Rows[0]["PT_FILE"].ToString(); string content1 = ds.Tables[0].Rows[0]["PT_FILE1"].ToString(); DeleteTFN(content); DeleteTFN(content1); string filesql = "DELETE FROM tb_files WHERE BC_CONTEXT = '" + content + "'"; string sql = "delete from TBMP_PRDCTTASKTOTAL where PT_CODE='" + code + "'"; string subsql = "delete from TBMP_PRDCTTASKDETAIL where PT_CODE='" + code + "'"; ltsql.Add(filesql); ltsql.Add(sql); ltsql.Add(subsql); } } DBCallCommon.ExecuteTrans(ltsql); Response.Redirect("TM_HZY_info.aspx"); }
/// <summary> /// 重新分工时的修改数据的绑定 /// </summary> /// <param name="id"></param> private void bindQntyInfo() { string selsql = "select AFI_QCMAN,AFI_QCMANNM from TBQM_APLYFORINSPCT where AFI_ID='" + qsaid + "'"; DataSet ds = DBCallCommon.FillDataSet(selsql); if (ds.Tables[0].Rows.Count > 0) { txtqcclerknmid.Value = ds.Tables[0].Rows[0]["AFI_QCMAN"].ToString(); txtqcclerknm.Value = ds.Tables[0].Rows[0]["AFI_QCMANNM"].ToString(); } }
/// <summary> /// 绑定过程检验的结果图 /// </summary> private void bindGridV1() { /************************根据检验时间升序排列***************************/ string sqlselect1 = "select * from TBQM_ISPCTRESULT where ISR_CODE='" + AFI_ID + "' AND ISR_NUM='0' ORDER BY ISR_DATE "; DataSet ds = DBCallCommon.FillDataSet(sqlselect1); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } }
//删除文件 protected void DeleteTFN(string context) { string sqlStr = "select fileName from tb_files where BC_CONTEXT='" + context + "'"; DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取指定文件的路径 //Response.Write(ds.Tables[0].Rows.Count); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string strFilePath = Server.MapPath("../Contract/") + ds.Tables[0].Rows[i][0].ToString(); File.Delete(strFilePath);//文件不存在也不会引发异常 } }
private void GVBind() { if (txtCS_CODE.Text == "") { txtCS_CODE.Text = id; } string sql = "select * from TBMA_FILES where SUPPLYID='" + txtCS_CODE.Text + "' "; DataSet ds = DBCallCommon.FillDataSet(sql); gvfileslist.DataSource = ds.Tables[0]; gvfileslist.DataBind(); gvfileslist.DataKeyNames = new string[] { "ID" }; }
private string bindNameByID(string id) { string sqlSelect = "select ST_NAME from TBDS_STAFFINFO where ST_ID='" + id + "'"; string st_name = string.Empty; using (DataSet ds = DBCallCommon.FillDataSet(sqlSelect)) { if (ds.Tables[0].Rows.Count > 0) { st_name = ds.Tables[0].Rows[0]["ST_NAME"].ToString(); } } return(st_name); }
private void GVBind() { if (txtCS_CODE.Text == "") { txtCS_CODE.Text = PC_PFT_ID_code; } string sql = "select * from PC_PurInforCom_Attach where PC_PFT_ID='" + txtCS_CODE.Text + "' "; DataSet ds = DBCallCommon.FillDataSet(sql); gvfileslist.DataSource = ds.Tables[0]; gvfileslist.DataBind(); gvfileslist.DataKeyNames = new string[] { "ID" }; }
void bindQCData() { string sql = "select DEP_CODE,DEP_NAME from TBDS_DEPINFO where DEP_CODE LIKE '03__'";//从部门信息表中读取质量部部门名称和部门编号 DataSet ds = DBCallCommon.FillDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { ddlSearch.DataSource = ds; ddlSearch.DataTextField = "DEP_NAME"; ddlSearch.DataValueField = "DEP_CODE"; ddlSearch.DataBind(); } ddlSearch.Items.Insert(0, new ListItem("全部", "0")); }
protected void GVBind(GridView gv) { string sql = "select * from View_CM_CusApply where CM_ID='" + id + "'"; DataTable dt = DBCallCommon.GetDTUsingSqlText(sql); if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; sql = "select * from tb_files where BC_CONTEXT='" + dr["CM_CONTEXT"].ToString() + "'"; DataSet ds = DBCallCommon.FillDataSet(sql); gv.DataSource = ds.Tables[0]; gv.DataBind(); gv.DataKeyNames = new string[] { "fileID" }; } }
public string[] GetCompletebytsaid(string prefixText, int count) { ///检测参数是否为空 if (string.IsNullOrEmpty(prefixText) == true || count <= 0) { return(null); } // 如果数组为空 if (autoCompleteWordList == null) { //读取数据库的内容 SqlConnection sqlConn = new SqlConnection(); sqlConn.ConnectionString = DBCallCommon.GetStringValue("connectionStrings"); sqlConn.Open(); DataSet ds = new DataSet(); DataTable glotb = new DataTable(); ds = DBCallCommon.FillDataSet("SELECT distinct TSA_ID as Expr1 from View_CM_FaHuo WHERE TSA_ID LIKE '%" + prefixText.Trim() + "%'"); glotb.Merge(ds.Tables[0]); glotb.AcceptChanges(); //读取内容文件的数据到临时数组 string[] temp = new string[glotb.Rows.Count]; int i = 0; foreach (DataRow dr in glotb.Rows) { temp[i] = dr["Expr1"].ToString(); i++; } Array.Sort(temp, new CaseInsensitiveComparer()); autoCompleteall = temp; //将临时数组的内容赋给返回数组 if (sqlConn.State == ConnectionState.Open) { sqlConn.Close(); } } int matchCount = autoCompleteall.Length >= count ? count : autoCompleteall.Length; string[] matchResultList = new string[matchCount]; if (matchCount > 0) { //复制搜索结果 Array.Copy(autoCompleteall, 0, matchResultList, 0, matchCount); } return(matchResultList); }
protected void GridView1_DataBound(object sender, EventArgs e) { foreach (GridViewRow gr in GridView1.Rows) { //绑定负责人 DropDownList ddldiaoduyuan = (DropDownList)gr.FindControl("ddl_fuzeren"); ddldiaoduyuan.Items.Clear(); ddldiaoduyuan.Items.Add(new ListItem("--请选择--", "")); string sqltxt = "select ST_CODE,ST_NAME from TBDS_STAFFINFO where ST_POSITION='采购员'"; DataSet ds = DBCallCommon.FillDataSet(sqltxt); foreach (DataRow dRow in ds.Tables[0].Rows) { ListItem listitem = new ListItem(dRow["ST_NAME"].ToString(), dRow["ST_CODE"].ToString()); ddldiaoduyuan.Items.Add(listitem); } } }
private void GVBind(string content) { string sql = "select * from tb_files where BC_CONTEXT='" + content + "'"; DataSet ds = DBCallCommon.FillDataSet(sql); if (action == "add") { gvfileslist.DataSource = ds.Tables[0]; gvfileslist.DataBind(); gvfileslist.DataKeyNames = new string[] { "fileID" }; } else if (action == "js") { gvfileslist1.DataSource = ds.Tables[0]; gvfileslist1.DataBind(); gvfileslist1.DataKeyNames = new string[] { "fileID" }; } }
private string getlocationcode() //一级地区编码 { string Code = ""; int code1 = 0; string sqltxt = "select CL_CODE from TBCS_LOCINFO where CL_FATHERCODE='ROOT'"; DataSet ds = DBCallCommon.FillDataSet(sqltxt); if (ds.Tables[0].Rows.Count > 1) { for (int i = 0; i <= ds.Tables[0].Rows.Count - 2; i++) { if (Convert.ToInt32(ds.Tables[0].Rows[i + 1]["CL_CODE"].ToString()) - Convert.ToInt32(ds.Tables[0].Rows[i]["CL_CODE"].ToString()) != 1) { code1 = Convert.ToInt32(ds.Tables[0].Rows[i]["CL_CODE"]) + 1; } else { continue; } } if (code1 == 0) { code1 = Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["CL_CODE"].ToString()) + 1; } if (code1 < 10) { Code = "0" + code1.ToString(); } else { Code = code1.ToString(); } } else if (ds.Tables[0].Rows.Count == 1) { Code = "02"; } else { Code = "01"; } return(Code); }
//下载 protected void imgbtndownload_Click(object sender, ImageClickEventArgs e) { //获取imgbtnDelete的ImageButton对象 ImageButton imgbtn = (ImageButton)sender; //引用imgbtnDelete控件的父控件上一级控件 GridViewRow gvr = (GridViewRow)imgbtn.Parent.Parent; GridView gv = (GridView)imgbtn.Parent.Parent.Parent.Parent; string idd = ((Label)gvr.FindControl("lbid")).Text; //获取文件真实姓名 string sqlStr = "select SAVEURL,FILENAME from OM_YONGYIN_Attach where ID='" + idd + "'"; //打开数据库 //Response.Write(sqlStr); DataSet ds = DBCallCommon.FillDataSet(sqlStr); //获取文件路径 string strFilePath = ds.Tables[0].Rows[0]["SAVEURL"].ToString() + @"\" + ds.Tables[0].Rows[0]["FILENAME"].ToString(); Response.Write(strFilePath); //判断文件是否存在,如果不存在提示重新上传 if (System.IO.File.Exists(strFilePath)) { System.IO.FileInfo file = new System.IO.FileInfo(strFilePath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name)); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.WriteFile(file.FullName); Response.Flush(); Response.End(); } else { filesError.Visible = true; filesError.Text = "文件已被删除,请通知相关人员上传文件!"; } }