日期:2014-05-17  浏览次数:20516 次

百分请教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);