sqldata da = new sqldata(); int id = 0; protected void Page_Load(object sender, EventArgs e) {
DataTable dt = new DataTable(); string a = Request.QueryString["id"]; a = a == null ? "0" : a; int id = Convert.ToInt32(a); Image1.ImageUrl = videoURL.Text;
sqldata da = new sqldata(); int id = 0; //此处申明了全局变量 protected void Page_Load(object sender, EventArgs e) {
DataTable dt = new DataTable(); string a = Request.QueryString["id"]; a = a == null ? "0" : a; // int id = Convert.ToInt32(a); //此处又申明了一重复id id = Convert.ToInt32(a); //应该这样给全局变量付值 或者用viewstate存储一下id 后边button_click事件调用此viewstate读到id Image1.ImageUrl = videoURL.Text;
int id = 0;
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string a = Request.QueryString["id"];
a = a == null ? "0" : a;
int id = Convert.ToInt32(a);
Image1.ImageUrl = videoURL.Text;
this.addtime.Text = DateTime.Now.ToString("yyyy-MM-dd");
if(id>0){
dt = GVDataBind(id).DataSet.Tables[0];
title.Text=dt.Rows[0][1].ToString();
contont.Text = dt.Rows[0][2].ToString();
videoURL.Text = dt.Rows[0][3].ToString();
range.Text = dt.Rows[0][4].ToString();
Button1.Text = "修改";
}
if(!IsPostBack){ Image1.ImageUrl = videoURL.Text;
DataSet ds = da.ExceDS("select * from Products");
type.DataSource = ds.Tables[0].DefaultView;
type.DataTextField = "title";
type.DataValueField = "id";
type.DataBind(); }
}
protected DataTable GVDataBind(int id)
{ string sql = "select * from Details where id=" + id; return da.ExceDS(sql).Tables[0];
}
protected void Button1_Click(object sender, EventArgs e)
{
if(id==0){
if(Image1.ImageUrl.Length==0){
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请上传图片!')</script>");
return;
} string title=Request["title"].ToString();
string addtime = Request["addtime"].ToString();
string contont = Request["contont"].ToString();
string img = Request["videoURL"].ToString();
string range = Request["range"].ToString();
int type =Convert.ToInt32(this.type.SelectedValue); //应用范围与产品分类
string sql = "insert into Details(title,contont,img,addtime,type,range) values ('" + title + "','" + contont + "','" + img + "','" + addtime + "'," + type + ",'" + range + "') ";
da.ExceSQL(sql);
string sql1 = " select top 1 [id] from [details] order by [id] desc";
Object abc = da.ExceSQLIden(sql1);
string sqltype = "insert into app_pro(app,pro,protype)values(" + range + "," + abc.ToString() + "," +type.ToString() + ")";
da.ExceSQL(sqltype);
da.connectClose();
Response.Redirect("productsCX.aspx",true);
}
if (id > 0) { string title = Request["title"].ToString();
string addtime = Request["addtime"].ToString();
string contont = Request["contont"].ToString();
string img = Request["videoURL"].ToString();
string range = Request["range"].ToString();
int type = Convert.ToInt32(this.type.SelectedValue);
string sql = "update Details set title='" + title + "',contont='"+contont+"',img='"+img+"',addtime='"+addtime+"',type="+type+",range='"+range+"'";
da.ExceSQL(sql);
string sql2 = " select top 1 [id] from [details] order by [id] desc";
Object abc = da.ExceSQLIden(sql2);
string sqltype1 = "update Details set app="+range+",pro="+abc.ToString()+",protype="+type.ToString()+"";
da.ExceSQL(sqltype1);
da.connectClose();
Response.Redirect("productsCX.aspx", true);
}
}
private DataTable GetFl(int id) { string fl = "select * from Products where id="+id;
return da.ExceDS(fl).Tables[0];
}
protected void type_SelectedIndexChanged(object sender, EventArgs e)
{
int id = Convert.ToInt32(this.type.SelectedValue);
type.DataSource = GetFl(id);
type.DataBind(); }
protected void UploadButton_Click(object sender, EventArgs e)
{
this.SaveImages();
Image1.ImageUrl = videoURL.Text;
} private Boolean SaveImages()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
string filePath = ""; string fileName = "";
string fileExtension = "";///
string fileUrl = Request.ApplicationPath;
string filea = HttpContext.Current.Request.Url.Host.ToString();
string fileport = ":" + Convert.ToInt32(Request.ServerVariables["server_port"]);
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{ HttpPostedFile postedFile = files[iFile];
filePath = System.Web.HttpContext.Current.Request.MapPath("~/video/");
fileName = System.IO.Path.GetFileName(postedFile.FileName); if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName); postedFile.SaveAs(filePath + fileName);
}
} videoURL.Text = "http://" + filea + fileport + fileUrl + "/video/" + fileName; return true;
}
catch (System.Exception Ex)
{
return false;
} }
sqldata da = new sqldata();
int id = 0; //此处申明了全局变量
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string a = Request.QueryString["id"];
a = a == null ? "0" : a;
// int id = Convert.ToInt32(a); //此处又申明了一重复id
id = Convert.ToInt32(a); //应该这样给全局变量付值 或者用viewstate存储一下id 后边button_click事件调用此viewstate读到id
Image1.ImageUrl = videoURL.Text;
this.addtime.Text = DateTime.Now.ToString("yyyy-MM-dd");
if(id>0){
dt = GVDataBind(id).DataSet.Tables[0];
title.Text=dt.Rows[0][1].ToString();
contont.Text = dt.Rows[0][2].ToString();
videoURL.Text = dt.Rows[0][3].ToString();
range.Text = dt.Rows[0][4].ToString();
Button1.Text = "修改";
}
id>0的时候是更新,有记录的话就更新 你所选择的那条记录,但前提是你必须根据你所选择的索引,得到你的操作行的ID(数据表中的ID).
name 1111 把1111更新成22222点更新他就出来22行name 2222是这样