原本功能一切正常。在表中添加了新的一列,修改过以后其他功能都可以用,就是没有办法上传图片了。
我用的是FORMVIEW。
前台
封面路径:
<img id="Img1" src= '<%#ResolveClientUrl("~/img/"+Eval("Image"))%>' runat="server" />
<asp:FileUpload ID="FileUploadPic" runat="server" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("Image") %>' />后台
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
FileUpload fileuploadPic = (FileUpload)FormView1.FindControl("fileuploadPic");
if(fileuploadPic.HasFile)
{
string ext = Path.GetExtension(fileuploadPic.FileName).ToLower();
if (ext == ".jpg" || ext == ".gif" || ext == ".jpeg" || ext == ".png")
{
fileuploadPic.SaveAs(Server.MapPath("~/img/" + fileuploadPic.FileName));
e.NewValues["Image"]= fileuploadPic.FileName;
}
else
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('上传文件类型错误,只允许jpeg,gif和png格式')", true);//页面加载时执行JavaScript脚本,页面写gettype就行,名称页面唯一就可以,true 为自动添加script标签
e.Cancel = true;
return;
}
求各位大神帮忙啊
我用的是FORMVIEW。
前台
封面路径:
<img id="Img1" src= '<%#ResolveClientUrl("~/img/"+Eval("Image"))%>' runat="server" />
<asp:FileUpload ID="FileUploadPic" runat="server" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("Image") %>' />后台
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
FileUpload fileuploadPic = (FileUpload)FormView1.FindControl("fileuploadPic");
if(fileuploadPic.HasFile)
{
string ext = Path.GetExtension(fileuploadPic.FileName).ToLower();
if (ext == ".jpg" || ext == ".gif" || ext == ".jpeg" || ext == ".png")
{
fileuploadPic.SaveAs(Server.MapPath("~/img/" + fileuploadPic.FileName));
e.NewValues["Image"]= fileuploadPic.FileName;
}
else
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('上传文件类型错误,只允许jpeg,gif和png格式')", true);//页面加载时执行JavaScript脚本,页面写gettype就行,名称页面唯一就可以,true 为自动添加script标签
e.Cancel = true;
return;
}
求各位大神帮忙啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货