如何向上和向下移动记录 [英] How to move records Up and Down

查看:84
本文介绍了如何向上和向下移动记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网格视图之外单击按钮(向上/向下)上下移动所选行。

请帮帮我。

I want to move the selected row Up and down on click of Buttons (Up/Down) which are outside the gridview.
Please help me.

推荐答案

与同一主题相关的上一个问题

如何使用asp.net在gridview中上下移动行? [ ^ ]

和jquary解决方案

使用jQuery& amp;上移或下移GridView行ASP.NET,C# [ ^ ]





previous question related to same topic
how to move rows up and down in gridview using asp.net?[^]
and jquary solution
Move Up or Move Down GridView Rows using jQuery & ASP.NET, C#[^]


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt =GetTable();
        GridView1.DataSource = dt;
        GridView1.DataBind();
        ViewState["Table"] = dt;
    }

}

protected void ButtonUp_Click(object sender, EventArgs e)
{
    int index = GridView1.SelectedIndex;
    if (index >0)
    {
          DataTable dtUp = (DataTable)ViewState["Table"];
          DataRow row = dtUp.NewRow();
          row.ItemArray = dtUp.Rows[index].ItemArray;
          dtUp.Rows.RemoveAt(index);
          dtUp.Rows.InsertAt(row, index - 1);
          dtUp.AcceptChanges();
          GridView1.DataSource = dtUp;
          GridView1.DataBind();
          ViewState["Table"] = dtUp;
    }
}

protected void ButtonDown_Click(object sender, EventArgs e)
{
    int index = GridView1.SelectedIndex;
    if (index < GridView1.Rows.Count)
    {
        DataTable dtdown = (DataTable)ViewState["Table"];
        DataRow row = dtdown.NewRow();
        row.ItemArray = dtdown.Rows[index].ItemArray;
        dtdown.Rows.RemoveAt(index);
        dtdown.Rows.InsertAt(row, index + 1);
        dtdown.AcceptChanges();
        GridView1.DataSource = dtdown;
        GridView1.DataBind();
        ViewState["Table"] = dtdown;
    }
}


这篇关于如何向上和向下移动记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆