日期:2014-05-17  浏览次数:20736 次

GridView中数据行上下移动
public partial class Sys_Test1 : System.Web.UI.Page
{
  SqlConnection conn = new SqlConnection("Data Source=172.16.2.46;Initial Catalog=SR;User ID=sa");
  SqlDataAdapter adapter;
  SqlDataAdapter adapter1;
  DataSet ds = new DataSet();
  static List<string[]> ListTable = new List<string[]>(); //泛型


  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  string SRNo = "BM2200809260019";  
  BindGridView(SRNo);  
  }
  }


  protected void BindGridView(string SRNo)
  {
  string sql = "select * from sr_getModuleSub(62) where vtype='03'"; //sr_getModuleSub()为一表值函数,从模板里取出数据
  adapter = new SqlDataAdapter(sql, conn);
  conn.Open();
  adapter.Fill(ds, "Module");
  GridView1.DataSource = ds.Tables[0].DefaultView;
  GridView1.DataBind();
  adapter1 = new SqlDataAdapter("select * from Sr_AppNode where vAppNo='" + SRNo + "'", conn);
  adapter1.Fill(ds, "AppNode");
  if (ds.Tables["AppNode"].Rows.Count != 0)
  {
  ListTable.Clear();
  for (int i = 0; i < ds.Tables["AppNode"].Rows.Count; i++)
  {
  ListTable.Add(new string[] { ds.Tables["AppNode"].Rows[i]["vAppNo"].ToString(), ds.Tables["AppNode"].Rows[i]["inode"].ToString(), ds.Tables["AppNode"].Rows[i]["Iseq"].ToString(), ds.Tables["AppNode"].Rows[i]["vway"].ToString(), ds.Tables["AppNode"].Rows[i]["vGoway"].ToString(), ds.Tables["AppNode"].Rows[i]["vAuditNo"].ToString() });
  } //添加数据到ListTable
  conn.Close();
  }
  }


  protected void BindGridView1(string SRNo)
  {
  string sql1 = "select * from sr_getAppNode('" + SRNo + "')"; //GridView中的节点修改后,不插入模板表,而是插入另一个表,再取出来
  adapter = new SqlDataAdapter(sql1, conn);
  conn.Open();
  adapter.Fill(ds);
  GridView1.DataSource = ds.Tables[0].DefaultView;
  GridView1.DataBind();
  conn.Close();
  }


  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  int index = Convert.ToInt32(e.CommandArgument.ToString());
  string SRNo = "BM2200809260019";
  if (e.CommandName == "up")
  {
  if (index > 0)
  {
  int nowid = index+1;
  int upside = index;

  for (int i = 0; i < ListTable.Count; i++)
  {
  if (Int32.Parse(ListTable[i][1].ToString()) == nowid)
  {
  ListTable[i][1] = "0";
  }
  else if (Int32.Parse(ListTable[i][1].ToString()) == index)
  {
  ListTable[i][1] = nowid.ToString();
  }
  }
  for (int k = 0; k < ListTable.Count; k++)
  {