dataTable1.DefaultView.Sort = "score desc";
dataTable1= _dtSource.DefaultView.ToTable();DataRow[] rows = dataTable1.Select(string.Format("no = {0}", txtNo.Text.Trim()));
if(rows.Lenght>0)
{
int index = _dtSource.Rows.IndexOf(drs[0]);//名次
}
dataTable1= _dtSource.DefaultView.ToTable();DataRow[] rows = dataTable1.Select(string.Format("no = {0}", txtNo.Text.Trim()));
if(rows.Lenght>0)
{
int index = _dtSource.Rows.IndexOf(drs[0]);//名次
}
dataTable1= dataTable1.DefaultView.ToTable();
然后根据输入的学号 查询,并弹出数据。
//设置功能
class Fruit
{
public string Name { get; set; }
public float Price { get; set; }
}
//窗体Load加载事件;
private void Frm_Main_Load(object sender, EventArgs e)
{
dgv_Message.DataSource = new List<Fruit>() {//绑定数据集合
new Fruit(){Name="苹果",Price=30},
new Fruit(){Name="橘子",Price=40},
new Fruit(){Name="鸭梨",Price=33},
new Fruit(){Name="水蜜桃",Price=31}};
dgv_Message.Columns[0].Width = 200;//设置列宽度
dgv_Message.Columns[1].Width = 170;//设置列宽度
dgv_Message.Columns[0].SortMode = //设置列排序模式
DataGridViewColumnSortMode.NotSortable;
dgv_Message.Columns[1].SortMode =//设置列排序模式
DataGridViewColumnSortMode.NotSortable;
}