日期:2014-05-18  浏览次数:20405 次

xmldatasource+gridview进行删除操作,数据库中的数据删除了,但是gridview不更新
我尝试了在page_load中添加gridview.databind(),发现这样添加后对数据库的操作九五小了。而如果把gridview.databind()放在删除按钮函数的末尾,则时好时坏。不知道为什么,请高手指教!
下面是部分代码:


protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                BtnDelete.Attributes.Add( "onclick ",   "return   confirm( '确定要删除这些记录吗? ') ");
                TextBox1.Text   =   "null ";
                if   (!IsPostBack)   {   GridView1.DataBind();   }
        }

protected   void   BtnDelete_Click(object   sender,   EventArgs   e)
        {
                int   i;
                String   sSearchRank;
                XmlDocument   XmlDoc   =   new   XmlDocument();
                XmlDoc.Load(Server.MapPath( "../XMLFile.xml "));
                XmlNode   XmlRoot   =   XmlDoc.DocumentElement;
                XmlNode   XmlSchNode;
                for   (i   =   0;   i   <   GridView1.Rows.Count;   i++)
                {
                        if   (((CheckBox)GridView1.Rows[i].FindControl( "ChkSel ")).Checked   ==   true)
                        {
                                sSearchRank   =   GridView1.DataKeys[i].Value.ToString();
                                XmlSchNode   =   XmlRoot.SelectSingleNode( "Record[@rank= ' "   +   sSearchRank   +   " '] ");
                                if   (XmlSchNode   !=   null)
                                {
                                        XmlSchNode.ParentNode.RemoveChild(XmlSchNode);
                                        String   bmpfilename   =   String.Format( "picsource/image{0}.bmp ",   sSearchRank);
                                        String   path   =   String.Format(Server.MapPath( "../ ")   +   bmpfilename);
                                        FileInfo   filedel