2 yushanrusheng yushanrusheng 于 2014.01.27 14:06 提问

做数据上移为什么单击后没反应

protected void BtnUpClick_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
OleDbConnection myconn = DB.CreateDB();
myconn.Open();

DataTable aFolderDocsTable = (DataTable)ViewState["id"];

//aFolderDoscTable是帮定在DataGrid里面的DataTable
if (DataGrid1.SelectedIndex == -1)
{
return;
}
if (DataGrid1.SelectedIndex == 0)
{
return;
}
if (DataGrid1.SelectedIndex > 0)
{
DataRow tempRow = aFolderDocsTable.NewRow();
//新增一条row,来保存所选定的DataRow

tempRow["id"] = aFolderDocsTable.Rows[DataGrid1.SelectedIndex]["id"];
//......//分别给这个row赋值
aFolderDocsTable.Rows.InsertAt(tempRow, DataGrid1.SelectedIndex - 1);
//插入新的row
aFolderDocsTable.Rows.RemoveAt(DataGrid1.SelectedIndex + 1);
//删除原来的row
DataGrid1.SelectedIndex = DataGrid1.SelectedIndex - 1;
//继续选定原来选定的行,只是位置上移了一位
DataGrid1.DataSource = aFolderDocsTable.DefaultView;
DataGrid1.DataBind();
//重新绑定
}
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!