进入编辑模式后。DataGrid突然变宽好多更改几个值后,点“更新”,竟然变成删除了郁闷几次后在DataGrid1_DeleteCommand里设了个断点,竟然真进去了我想,可能是浏览模式下"删除"的位置与编辑模式下的"更新"重了...用EditTemplate应该可以解决另外,顺便问一下,EditTemplate中怎么放控件使处于编辑状态时DataGrid的大小不变

解决方案 »

  1.   

    to wengnet(西门吹雪):
    在更新和删除的时候应该设置命令参数,然后在操作的时候做判断
    ----------
    DataGrid里几个命令本来就是分开的。protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = e.Item.ItemIndex;
            DataGrid1DataBind();  // 自定义函数
        }    protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = -1;
            DataGrid1DataBind();        }    protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            string sID = e.Item.Cells[0].Text;
            string sProvID = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
            string sNam = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
            string sSQL = "update city set ProvID='"+sProvID
                +"',cityNam='"+sNam+"' where cityID='"
                + sID+"'";
            Function.ExecuteSQL(sSQL);
            DataGrid1DataBind();
            DataGrid1.EditItemIndex = -1;   
        }    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            string s = e.Item.Cells[0].Text;
            string sSQL = "delete from city where cityID='"+s+"'";                  Function.ExecuteSQL(sSQL);  // 自定义函数
            DataGrid1DataBind();    
        }
      

  2.   

    好乱啊...我转换成模板列后,点"更新"后跳到DataGrid1_EditCommand里去了.我晕啥回事捏>?