博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

DataTable接受更改 dt.AcceptChanges()

Posted on 2008-01-29 11:14  孤峰皓月  阅读(1155)  评论(0编辑  收藏  举报

        DataTable dt = objDB.GetDataTable("InviteManageList", pamSearchUser);
        dt.Columns.Add("State2", typeof(String));

        foreach (DataRow dr in dt.Rows)
        {
            int intType=0;

            if (dr["State"].ToString() == "0" && Convert.ToDateTime(dr["AddTime"].ToString()).AddHours(72) > System.DateTime.Now)
            {
                dr["State2"] = "<img src='../image/red_h.gif'> 邀约等待";
                intType = 1;
            }
            else if (dr["State"].ToString() == "0" && Convert.ToDateTime(dr["AddTime"].ToString()).AddHours(72) <= System.DateTime.Now)
            {
                dr["State2"] = "<img src='../image/gray_h.gif'> 邀约过时";
                intType = 2;
            }
            else if (dr["State"].ToString() == "2")
            {
                dr["State2"] = "<img src='../image/gray_h.gif'> 邀约被拒";
                intType = 3;
            }
            else if (dr["State"].ToString() == "1" && dr["AcceptTime"] != null && Convert.ToDateTime(dr["AcceptTime"].ToString()).AddHours(72) > System.DateTime.Now)
            {
                dr["State2"] = "<img src='../image/red_h2.gif'> 交换等待";
                intType = 4;
            }
            else if (dr["State"].ToString() == "1" && dr["AcceptTime"] != null && Convert.ToDateTime(dr["AcceptTime"].ToString()).AddHours(72) <= System.DateTime.Now)
            {
                dr["State2"] = "<img src='../image/gray_h.gif'> 交换过时";
                intType = 5;
            }
            else if (dr["State"].ToString() == "3")
            {
                dr["State2"] = "<img src='../image/red_h3.gif'> 交换成功";
                intType = 6;
            }

            if(ddlType.SelectedValue != "0" && ddlType.SelectedValue != intType.ToString())
            {
                dr.Delete();
            }

        }

        dt.AcceptChanges();

        this.grdFriendToMe.VirtualItemCount = dt.Rows.Count;
        this.grdFriendToMe.CurrentPageIndex = pageIndex;
        this.grdFriendToMe.DataSource = dt;
        this.grdFriendToMe.DataBind();