• 关于dataTable上移或下移


    //记录上移或下移
            private void ReccordData(DataTable dt, string TypeValue,int index)
            {
                DataRow dr = dt.Rows[index]; //表示要移动的当前行对象
                string strValu = dr[0].ToString(); //当前行对象某一例的值(我这里默认是0列) strVal是记录此值
                dt.Rows.RemoveAt(index); //先删除它,在插入
                DataRow drnew = dt.NewRow();
                drnew["Engilsh"] = strValu;
                if (TypeValue == "UPEnglish") //说明是上移或者下移
                {
                    dt.Rows.InsertAt(drnew, index - 1); //上移就在自已索引位置减1
                }
                else
                {
                    dt.Rows.InsertAt(drnew, index+1); //反之下移就在当前位加1
                }
                gridViewInsertEnglishBind();// 绑定数据
            }
    //下面是行命令事件
          protected void gridViewInTruEnglish_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                    case "DeleteEnglish": // 删除
                       //  int row = ((GridViewRow)((ImageButton)sender).NamingContainer).RowIndex;
                         GridViewRow drvEnglishDelet = ((GridViewRow)(((ImageButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                         dtInStroEnglish.Rows.RemoveAt(drvEnglishDelet.RowIndex);
                         gridViewInsertEnglishBind();// 绑定数据
    
    
                        break;
                    case "DownEnglish": // 下降
                           GridViewRow drvDownEnglish = ((GridViewRow)(((ImageButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                           int indexDown = drvDownEnglish.RowIndex;//当前行的索引
                           if (indexDown == dtInStroEnglish.Rows.Count-1) //表示最下面了,索引从0开始
                           {
                               return;
                           }
                           else
                           {
                               
                               ReccordData(dtInStroEnglish, "UPEnglish", indexDown);
    
                           }
    
                        break;
                    case "UPEnglish": // 上升
                          GridViewRow drvUPEnglish = ((GridViewRow)(((ImageButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                          int indexUp = drvUPEnglish.RowIndex;//当前行的索引
                          if (indexUp == 0) //当它本身位置是第一个当然是不可以上移的
                          {
                              return;
                          }
                          else
                          {                 
                              ReccordData(dtInStroEnglish, "UPEnglish", indexUp);
                          }
                        break;
                }
            }
    

  • 相关阅读:
    hihocoder-1014 Trie树
    51Nod-1265 四点共面
    cf466B Wonder Room
    2014.9.13模拟赛【数位和乘积】
    2014.9.13模拟赛【环上的游戏】
    bzoj2719[Violet 4]银河之星
    wikioi1450 xth的旅行
    poj2352 stars
    2014.9.6模拟赛【藏妹子之处】
    2014.9.6模拟赛【工资】
  • 原文地址:https://www.cnblogs.com/yzenet/p/2747562.html
Copyright © 2020-2023  润新知