当前位置: 代码迷 >> ASP.NET >> 百分请问System.Web.UI.WebControls.TextBox
  详细解决方案

百分请问System.Web.UI.WebControls.TextBox

热度:7379   发布时间:2013-02-25 00:00:00.0
百分请教System.Web.UI.WebControls.TextBox?
我添加内容的时候,有的不写。数据库字段里会出现System.Web.UI.WebControls.TextBox

还有就是我点编辑后我以前上传好的图片路径也变成了System.Web.UI.WebControls.TextBox。希望高手帮一下忙,谢谢了。

我的代码如下:
C# code
using System;using System.Data;using System.IO;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.Data.SqlClient;public partial class admin_AddNew : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        pageload();    }    private void pageload()    {       //网页加载        if (!IsPostBack)        {            //CommFun.IsAdmin();            string strqry;            DBFun.FillDwList(dw_ProductClass,"select Id,Name from BigClass");            string Action=Request.QueryString["Action"];            string id =Request.QueryString["Id"];            string allid=Request.QueryString["AllId"];            if (Action=="Edit"&& id !=null)            {               //显示信息并加以修改                strqry=string .Format("select * from T_News where id={0}",id);                DataRow dr =DBFun .GetDataView (strqry).Table.Rows[0];                tb_ProductName.Text=dr["Title"].ToString();                dw_ProductClass.Text=dr["Name"].ToString();                tb_ReadCount.Text=dr["ReadCount"].ToString();                tb_PicUrl .Text =dr["ProductPic"].ToString();                tb_VideoUrl.Text= dr["VideoUrl"].ToString();                tb_PicUrl.Text = dr["PlayUrl"].ToString();                FreeTextBox1.Text=dr["Content"].ToString();                img_pic.Src="..\\image\\"+dr["ProductPic"].ToString();                pan_Add.Visible =false;                pan_Edit.Visible =true;                btn_Ok .Text="修改";            }            else            {              pan_Add.Visible = true;              pan_Edit.Visible = false;              btn_Ok.Text = "添加";              img_pic.Visible = false;                        }                }    }    protected void btn_Ok_Click(object sender, EventArgs e)    {        //修改        modify();    }    private void modify()    {        string strsql;        if (btn_Ok.Text == "修改")        {            string id = Request.QueryString["id"];            if (id == null || id == "")                return;            string img_url;            img_url = img(myfileEdit);            if (img_url == "")            {                img_url = tb_PicUrl.Text;                if (img_url == "")                    img_url = "nopic.jpg";//如果不上传!为默认图片              }            strsql = string.Format("Update T_News set Title='{0}',BigClassId={1},Name='{2}'," + " ProductPic='{3}',ReadCount={4},VideoUrl='{5}',PlayUrl='{6}',Content='{7}' where id ={8}", tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text, img_url, tb_ReadCount.Text, tb_VideoUrl.Text,tb_PlayUrl,FreeTextBox1.Text.Replace("'", "''"), id);            if (DBFun.ExecuteUpdate(strsql))            {                Response.Write("<script>alert('修改成功!');window.location.href='AddNew.aspx?Action=Edit&ID=" + id + "';</script>");            }            else            {                Response.Write("<script>alert('修改失败!请确认输入是否正确。');</script>");            }        }        else        {            //添加            string img_url;            img_url = img(myfileAdd);            if (img_url == "")                img_url = "nopic.jpg";            strsql = string.Format("Insert into [T_News] (Title,BigClassId,Name,"                   + "ProductPic,ReadCount,VideoUrl,PlayUrl,Content) values('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}')",                   tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text,                   img_url, tb_ReadCount.Text,tb_VideoUrl, tb_PlayUrl.Text, FreeTextBox1.Text.Replace("'", "''"));            if (DBFun.ExecuteUpdate(strsql))            {                string NewId = DBFun.SearchValue("Select Max(id) from T_News");                Response.Write("<script>alert('添加成功!');window.location.href='AddNew.aspx?Action=Edit&ID=" + NewId + "';</script>");            }            else            {                Response.Write("<script>alert('添加失败!请确认输入是否正确!');</script>");            }        }    }    private string img(System.Web.UI.HtmlControls.HtmlInputFile Fupload)    {        //文件上传        try        {            if (Fupload.PostedFile.FileName == "")                return "";            string dir = DateTime.Now.ToString("yyyyMM");            if (!Directory.Exists(Server.MapPath("..\\image\\") + dir))            {                Directory.CreateDirectory(Server.MapPath("..\\image\\") + dir);                if (!Directory.Exists(Server.MapPath("..\\image\\") + dir))                    return "";            }            Random rd = new System.Random();            string filename;            string extname;            if (Fupload.PostedFile.FileName != "")            {                extname = Fupload.PostedFile.FileName.Substring(Fupload.PostedFile.FileName.LastIndexOf(".") + 1).ToUpper();                if ("JPG|GIF|BMP|PNG".IndexOf(extname) == -1)                {                    return "";                }                filename = dir + "\\" + DateTime.Now.ToString("yyyyMM") + rd.Next(1000).ToString() + "." + extname;                Fupload.PostedFile.SaveAs(Server.MapPath("..\\image\\") + filename);                return filename;            }            return "";        }        catch { return ""; }    }}
  相关解决方案