// 根据ID选中行,并将选中行显示在GridView最顶端
protected void SelectRowByID(DataGridView dgv, string ID)
{
//根据GridView某字段的值获得行号
DataRow[] rows = (dgv.DataSource as DataTable).Select("ID='" + ID + "'");
if (rows.Length > 0)
{
int findRow = (dgv.DataSource as DataTable).Rows.IndexOf(rows[0]);
dgv.ClearSelection();
if (findRow != -1)
{
dgv.FirstDisplayedScrollingRowIndex = findRow;//将此行滚动到GridView最项端
}
dgv.Rows[findRow].Selected = true;
}
}