看下这个例子我随手写的前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mx.aspx.cs" Inherits="mx" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table style="width: 488px; height: 192px">
<tr>
<td style="width: 100px; height: 13px">
姓名:</td>
<td style="width: 100px; height: 13px">
<input id="Text1" runat="server" type="text" /></td>
<td style="width: 100px; height: 13px">
</td>
</tr>
<tr>
<td style="width: 100px; height: 10px">
感言:</td>
<td style="width: 100px; height: 10px">
<textarea id="TextArea1" runat="server" style="width: 336px; height: 96px"></textarea></td>
<td style="width: 100px; height: 10px">
</td>
</tr>
<tr>
<td rowspan="2" style="width: 100px">
图片:</td>
<td style="width: 100px; height: 144px">
<img id="IMG1" runat="server" src="" /></td>
<td style="width: 100px; height: 144px">
</td>
</tr>
<tr>
<td style="width: 100px; height: 15px">
<input id="File1" runat="server" type="file" /></td>
<td style="width: 100px; height: 15px">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
</tr>
</table>
</form>
</body>
</html>
后台
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class mx : System.Web.UI.Page
{
jxcapital.DBConn conn = new jxcapital.DBConn();
DataSet ds = new DataSet();
StringBuilder sd = new StringBuilder(); protected void Page_Load(object sender, EventArgs e)
{
string strsql = "";
string id=Request.QueryString["id"];
strsql = "select [name],[body],[url],[jl] from mx where id='"+ id.ToString() +"'";
ds = conn.ExecuteQuery(strsql);
conn.Close();
this.Text1.Value = ds.Tables[0].Rows[0].ItemArray[0].ToString();
this.TextArea1.Value=ds.Tables[0].Rows[0].ItemArray[1].ToString();
IMG1.Src = ds.Tables[0].Rows[0].ItemArray[2].ToString();
} protected void Button1_Click(object sender, EventArgs e)
{
string id=Request.QueryString["id"];
string strFileName = this.File1.PostedFile.FileName;
int nLength = strFileName.Length - (strFileName.LastIndexOf("\\") + 1);
strFileName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1,nLength);
//string strpath = Server.MapPath("\\") + "upimg\\";
string strpath = MapPath("down") + "\\";
File1.PostedFile.SaveAs(strpath + strFileName);
strsql="update [mx] set name='" + name.ToString() + "',name='" + name.ToString() + "' ,where id='" + id.ToString() + "'"
}
protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
{ }
}
在项目中建一个down的文件夹
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mx.aspx.cs" Inherits="mx" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table style="width: 488px; height: 192px">
<tr>
<td style="width: 100px; height: 13px">
姓名:</td>
<td style="width: 100px; height: 13px">
<input id="Text1" runat="server" type="text" /></td>
<td style="width: 100px; height: 13px">
</td>
</tr>
<tr>
<td style="width: 100px; height: 10px">
感言:</td>
<td style="width: 100px; height: 10px">
<textarea id="TextArea1" runat="server" style="width: 336px; height: 96px"></textarea></td>
<td style="width: 100px; height: 10px">
</td>
</tr>
<tr>
<td rowspan="2" style="width: 100px">
图片:</td>
<td style="width: 100px; height: 144px">
<img id="IMG1" runat="server" src="" /></td>
<td style="width: 100px; height: 144px">
</td>
</tr>
<tr>
<td style="width: 100px; height: 15px">
<input id="File1" runat="server" type="file" /></td>
<td style="width: 100px; height: 15px">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
</tr>
</table>
</form>
</body>
</html>
后台
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class mx : System.Web.UI.Page
{
jxcapital.DBConn conn = new jxcapital.DBConn();
DataSet ds = new DataSet();
StringBuilder sd = new StringBuilder(); protected void Page_Load(object sender, EventArgs e)
{
string strsql = "";
string id=Request.QueryString["id"];
strsql = "select [name],[body],[url],[jl] from mx where id='"+ id.ToString() +"'";
ds = conn.ExecuteQuery(strsql);
conn.Close();
this.Text1.Value = ds.Tables[0].Rows[0].ItemArray[0].ToString();
this.TextArea1.Value=ds.Tables[0].Rows[0].ItemArray[1].ToString();
IMG1.Src = ds.Tables[0].Rows[0].ItemArray[2].ToString();
} protected void Button1_Click(object sender, EventArgs e)
{
string id=Request.QueryString["id"];
string strFileName = this.File1.PostedFile.FileName;
int nLength = strFileName.Length - (strFileName.LastIndexOf("\\") + 1);
strFileName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1,nLength);
//string strpath = Server.MapPath("\\") + "upimg\\";
string strpath = MapPath("down") + "\\";
File1.PostedFile.SaveAs(strpath + strFileName);
strsql="update [mx] set name='" + name.ToString() + "',name='" + name.ToString() + "' ,where id='" + id.ToString() + "'"
}
protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
{ }
}
在项目中建一个down的文件夹
解决方案 »
- C#写WORD文档相似度
- 求助:给按钮添加动态事件
- .net出错处理的问题!!
- 急死了啊 请大哥大姐们来帮忙啊 ~~~~~~~~快啊救命啊 老板一直在拿着我骂 快99啊
- 【菜鸟提问】split怎么用来截字符串啊?帮助上看的有点糊涂
- 点了dataGrid一列头后,记录产生了排序,顺序变后,新的记录怎么访问?
- 下拉列表无刷新联动--如何后台获取联动下拉列表的值
- (WebBrowser 自动点击问题)200分求助大神!!!网页模拟点击问题!!
- 绿盾把文件放哪了
- 我的panel控件突然跳转不了了,代码没动,找不出来哪错的
- Grove 如何实现将表数据显示在listview中?
- 为何不能引用Microsoft.Office.Interop.Word名称空间?
jxcapital.DBConn conn = new jxcapital.DBConn();
DataSet ds = new DataSet();
StringBuilder sd = new StringBuilder();不要
只要 Button1_Click这段是上传
if (imgUpload.PostedFile.FileName !="")
换成
if(Request["imgUpload"] != null && Request["imgUpload"].ToString() != "")
试一下
也想用ajax上传图片
看样子现在没有招呀
有没有什么什么可以用的组件什么,直接实现异步上传呢
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="DV1" />
</Triggers>
</asp:UpdatePanel>所以只能在 updatepanel 中加了PostBackTrigger 使上传时触发 整页的post
除DV1之外的还是 部分更新
http://www.mybuffet.cn