| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1751 人关注过本帖
标题:手动绑定DetailsView编辑时,数据无法更新
只看楼主 加入收藏
luoye820116
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2010-10-10
结帖率:40%
收藏
已结贴  问题点数:3 回复次数:3 
手动绑定DetailsView编辑时,数据无法更新
我手动绑定DetailsView时,但是运行时,单击编辑按钮,修改表中数据后,数据更新不了,还是原来未修改的原因,不知道什么原因,代码如下,希望大家能指导下
 public partial class CheckResult : System.Web.UI.Page
    {

        SqlConnection sqlcon;

        string strCon = "Data Source=.;Initial Catalog=dkkDB;Integrated Security=True;Uid=sa;Pwd=123456 ";

        private void Bind()
        {
            string ID = Session["name"].ToString();
            string sqlstr = "select * from dkk_companyinfo where orgcode =" + ID;
            sqlcon = new SqlConnection(strCon);
            SqlDataAdapter adp = new SqlDataAdapter(sqlstr, sqlcon);
            DataSet mys = new DataSet();
            sqlcon.Open();
            adp.Fill(mys, "dkk_companyinfo");
            DetailsView1.DataSource = mys;
            DetailsView1.DataKeyNames = new string[] { "orgcode" };
            DetailsView1.DataBind();
            sqlcon.Close();
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        protected void DetailsView_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
        {
            DetailsView1.PageIndex = e.NewPageIndex;
        }

        protected void DetailsView1_Deleting(object sender, DetailsViewDeleteEventArgs e)
        {
            string charAreaCode = this.DetailsView1.DataKey.Value.ToString();
            Bind();
        }

        protected void DetailsView1_ModeChaning(object sender, DetailsViewModeEventArgs e)
        {
            this.DetailsView1.ChangeMode(e.NewMode);
            Bind();
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
           string charAreaCode = this.DetailsView1.DataKey.Value.ToString();
         
            dkk_Companyinfo Comp = new dkk_CompanyinfoDAL().Selctbyid(charAreaCode);
            int i;
             = charAreaCode;
            for (i = 0; i < e.NewValues.Count;i++ )
            {
                e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString());
            }
            for (i = 0; i < e.NewValues.Count-1; i++)
            {
                switch (i)
                {
                    case 0: = e.NewValues[i].ToString(); break;
                    case 1: = e.NewValues[i].ToString(); break;
                    case 2: Comp.Txadress = e.NewValues[i].ToString(); break;
                    case 3: Comp.Postcode = e.NewValues[i].ToString(); break;
                    case 4: Comp.Telephone = e.NewValues[i].ToString(); break;
                    case 5: Comp.Faxnumber = e.NewValues[i].ToString(); break;
                    case 6: Comp.Mail = e.NewValues[i].ToString(); break;
                    case 7: Comp.Date = Convert.ToDateTime(e.NewValues[i]); break; ;
                    case 8: Comp.Character = e.NewValues[i].ToString(); break;
                    case 9: Comp.Type = e.NewValues[i].ToString(); break;
                    case 10: Comp.Registercode = e.NewValues[i].ToString(); break;
                    case 11: Comp.Duedate = Convert.ToDateTime(e.NewValues[i]); break;
                    case 12: Comp.Financecode = e.NewValues[i].ToString(); break;
                    case 13: Comp.Division = e.NewValues[i].ToString(); break;
                    case 14: Comp.Classfied = e.NewValues[i].ToString(); break;
                    case 15: Comp.Sqare = float.Parse(e.NewValues[i].ToString()); break;
                    case 16: Comp.Owner = e.NewValues[i].ToString(); break;
                    default: break;
                }
            }
            if(new dkk_CompanyinfoDAL().Update(Comp))
            {
                 ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('更新成功')</script>");
           
            }
            new dkk_CompanyinfoDAL().Update(Comp);
            Bind();
        }

        protected void DetailView1_Inserting(object sender, DetailsViewInsertEventArgs e)
        {
            int i;
            for (i = 0; i < e.Values.Count; i++)
            {
                if (e.Values[i] != null)
                {
                    e.Values[i] = Server.HtmlEncode(e.Values[i].ToString());
                }
            }
            Bind();
        }
    }
搜索更多相关主题的帖子: 绑定 DetailsView 数据 
2010-11-02 20:22
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:1 
看代码更新结束后确实调用了Bind方法 会不会更新失败呢 建议楼主跟个断点看看

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-11-03 10:25
sjpr
Rank: 1
等 级:新手上路
帖 子:4
专家分:6
注 册:2010-11-3
收藏
得分:1 
设断点 调试哦。















[url=http://www.]江西眼科医院[/url]

[ 本帖最后由 sjpr 于 2010-11-3 11:45 编辑 ]

江西眼科医院
2010-11-03 11:44
jackie0609
Rank: 1
等 级:新手上路
帖 子:12
专家分:1
注 册:2010-11-9
收藏
得分:0 
把if(!IsPageBack){

}

去掉试一试吧!
2010-11-12 11:12
快速回复:手动绑定DetailsView编辑时,数据无法更新
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021581 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved