你的BuildTBlCommand是根据Basedatagrid1的哪一个属性来执行操作的?
问题应该是出在这个函数。
还有HidMessageIdList.Value起什么作用,他是否与BuildTBlCommand有关?

解决方案 »

  1.   

    to  amandag,vainnetwork    我点了编辑如代码所写,Basedatagrid1.EditItemIndex = e.Item.ItemIndex;做了如下设置,然后页面是textbox的显示模式,保留有原来的值,而且我当初也怀疑过可能默认有更改,所以我尝试特意在删除的操作代码 Basedatagrid1.EditItemIndex=e.Item.ItemIndex;又设置了当前值,或者读取原有的设定值,依然是同样的问题to liufuyahong     datagird控件我是刚用,不是相当熟悉,在此控件上我绑定了2个按钮列,对显示出来的每一行数据进行,编辑,或删除操作,因为实际跟数据库相关联的代码我是批量处理,所以,它(按钮列)实际的操作只是更改当前行的一个列值,我无法取到datagird绑定的datatable(直接采用读取datagrid.datasource属性),所以采用BuildTBlCommand函数(利用datagrid.Items[i].Cells[0])每行每列的读形成一个datatable;  HidMessageIdList.Value 这个text的值主要是保存,datagrid对应项的记录的操作符号,比如是对数据库删除,还是修改记录的作用!批操作的一个信息存储!
      
      读完我进行了重新绑定,要不然,datagrid的显示就是空的了!难道问题出在重新绑定上,我先按照这个思路好好看看,设定的编辑值是否保留!
      

  2.   

    to liufuyahong 
     我无法直接从datagird.datasource中读取dt(未修改和已经修改过的),解决绑定为空的现象的函数代码!
     //根据datagrid的datatable选项生成dt
            private DataTable BuildTBlCommand(BaseDataGrid bd,string readtype)
            {
    this.dt=new DataTable();
    dt.Columns.Add("CategoryID");
                dt.Columns.Add("CategoryType");
    dt.Columns.Add("CategoryName");
    dt.Columns.Add("MaxNumForAll");
    dt.Columns.Add("MaxNumForPerContact");
    dt.Columns.Add("MaxNumForPubContact");
    dt.Columns.Add("LastUpdate");
    dt.Columns.Add("OprationType"); StoreIndexForDel(this.HidMessageIdList.Value);
    StoreIndexForUpd(this.HidMessageIdOne.Value);         for(int i=0;i<bd.Items.Count;i++)
             {
    DataRow row1=this.dt.NewRow();
    if (bd.EditItemIndex==i && readtype=="TextBox")
    //if (readtype=="TextBox")
    {
    row1["CategoryID"]=bd.Items[i].Cells[0].Text;
    row1["CategoryType"]=bd.Items[i].Cells[8].Text;
    row1["CategoryName"]=((TextBox)bd.Items[i].Cells[1].Controls[0]).Text;
    row1["MaxNumForAll"]=((TextBox)bd.Items[i].Cells[2].Controls[0]).Text;
    row1["MaxNumForPerContact"]=((TextBox)bd.Items[i].Cells[3].Controls[0]).Text;
    row1["MaxNumForPubContact"]=((TextBox)bd.Items[i].Cells[4].Controls[0]).Text;
    row1["LastUpdate"]=bd.Items[i].Cells[5].Text;
                        //修正"U"操作字段
    if (this.updStore.Length>0)
    {
    for(int j=0;j<this.updStore.Length-1;j++)
    {
    if (Convert.ToInt16(this.updStore[j])==i)
    {
    row1["OprationType"]="U";
    break;
    }
    }
    }
    else
    {
    row1["OprationType"]="";
    }
    this.dt.Rows.Add(row1);
    }
    else
    {
    row1["CategoryID"]=bd.Items[i].Cells[0].Text;
    row1["CategoryType"]=bd.Items[i].Cells[8].Text;
    row1["CategoryName"]=bd.Items[i].Cells[1].Text;
    row1["MaxNumForAll"]=bd.Items[i].Cells[2].Text;
    row1["MaxNumForPerContact"]=bd.Items[i].Cells[3].Text;
    row1["MaxNumForPubContact"]=bd.Items[i].Cells[4].Text;
    row1["LastUpdate"]=bd.Items[i].Cells[5].Text;
    if (this.delStore.Length>0)
    {
    for(int j=0;j<this.delStore.Length-1;j++)
    {
         if (Convert.ToInt16(this.delStore[j])==i)
         {
          row1["OprationType"]="D";
    break;
         }
    }
    }
    else
    {
    row1["OprationType"]=bd.Items[i].Cells[9].Text;
    }
    this.dt.Rows.Add(row1);
    }
             }
    return this.dt;
            }