private void gv01_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
//......
do something
}GridView里有一个inputfile:file01,我想当file01.PostedFile.ContentLength>0时才执行gv01_RowUpdating事件,这个怎样处理,在哪处理?谢谢
{
//......
do something
}GridView里有一个inputfile:file01,我想当file01.PostedFile.ContentLength>0时才执行gv01_RowUpdating事件,这个怎样处理,在哪处理?谢谢
{
if (1 == 1) // 这里是你的条件。
{
e.Cancel = true; Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('数据编辑取消')</script>";
Page.Controls.Add(txtMsg);
}
}
private void gv01_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
string fname,firstname,filefullname,savePath;
GridViewRow erow=gv01.Rows[gv01.EditIndex];
savePath=Server.MapPath("..\\Attachments\\");
HtmlInputFile file01=(HtmlInputFile)erow.Cells[2].Controls[1];
if(file01.PostedFile.ContentLength>0)
{
File.Delete(savePath+erow.Cells[1].Text);
fname=System.IO.Path.GetFileName(file01.PostedFile.FileName);
firstname=System.IO.Path.GetFileNameWithoutExtension(file01.PostedFile.FileName);
filefullname=DateTime.Now.ToString("yyyymmddhhss")+"_"+fname;
try
{
e.NewValues["fileno"]=erow.Cells[0].Text;
e.NewValues["att"]=filefullname;
file01.PostedFile.SaveAs(savePath+filefullname);
}
catch(Exception ex)
{
throw(ex);
}
}
else
{
Response.Write(@"<script>alert('請選擇附件!')</script>");
e.Cancel=false;
}
}如果我没有加附件,即file01.PostedFile.ContentLength>0为空时,会报错:
必須宣告變數 '@att'。
描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。 例外詳細資訊: System.Data.SqlClient.SqlException: 必須宣告變數 '@att'。
办法1 用 JS 控制
办法2 读取值,条件不符合就直接 retuen;
這個辦法和我的代碼是不是一樣的?不一樣又要怎樣弄?謝謝!
{
paren = obj.parentElement;
return parseInt(paren.cells[?].firstChild.PostedFile.ContentLength);
}? 是你 inputfile 所在单元格的列
PostedFile.ContentLength 你说的这个属性,我也没找到,你自己调试一下,大体的思路就是这个,先找到你要的数据,然后根据结果返回是否请求事件。
这里写错了