xiaolinzi

避风港

DetailsView中编辑内容的设置内容和获取内容的方法

一.把内容设置到DetailsView中去
    一般都是在DetailsView中先添加一个TemplateField模板列,然后选择自己添加的模板列, 在模板列的EditItemTemplate中在添加自己所需要用于编辑的控件。如:TextBox , DataList

二.把显示在DetailsView中的数据获取出来
DetailsView 的ItemUpdating的事件中中写。
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        //取消DetailsView1_ItemUpdating默认的方法
        e.Cancel = true;

        EnterPrise objEnterPrise = new EnterPrise();
        OperEnterPrise objOep = new OperEnterPrise();
        //从文本框里面获取用户更改后的值
        objEnterPrise.EP_Id = Convert.ToInt32(e.Keys["EP_Id"]);
        objEnterPrise.EP_Name = ((TextBox)DetailsView1.FindControl("txtName")).Text;
        objEnterPrise.EP_Kind = ((TextBox)DetailsView1.FindControl("txtKind")).Text;
        objEnterPrise.EP_Introduction = ((TextBox)DetailsView1.FindControl("txtIntroduction")).Text;
        objEnterPrise.EP_Deputy = ((TextBox)DetailsView1.FindControl("txtDeputy")).Text;
        objEnterPrise.EP_Address = ((TextBox)DetailsView1.FindControl("txtAddress")).Text;
        objEnterPrise.EP_Phone = ((TextBox)DetailsView1.FindControl("txtPhone")).Text;
        objEnterPrise.EP_NetStation = ((TextBox)DetailsView1.FindControl("txtNetStation")).Text;
        objEnterPrise.EP_Image = ((TextBox)DetailsView1.FindControl("txtImage")).Text;
        objEnterPrise.EP_SendTime = ((TextBox)DetailsView1.FindControl("txtSendTime")).Text;

        if (objOep.UpdateEnterPrise(objEnterPrise))
        {
            Page.RegisterStartupScript("msg", "<script>alert('更新成功!!!')</script>");
            e.Keys["EP_Id"] = "";
            ((TextBox)DetailsView1.FindControl("txtName")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtKind")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtIntroduction")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtDeputy")).Text = "";
            objEnterPrise.EP_Address = ((TextBox)DetailsView1.FindControl("txtAddress")).Text = "";
            objEnterPrise.EP_Phone = ((TextBox)DetailsView1.FindControl("txtPhone")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtNetStation")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtImage")).Text = "";
            ((TextBox)DetailsView1.FindControl("txtSendTime")).Text = "";

            this.Bindbing();
        }
        else
        {
            Page.RegisterStartupScript("msg", "<script>alert('数据有误,更新失败!!!')</script>");
        }

    }

posted on 2008-04-20 11:28  小林子  阅读(1688)  评论(0编辑  收藏  举报

导航