Listview控件获取当前行的行号和主键

来源:互联网 发布:office for mac下架了? 编辑:程序博客网 时间:2024/05/20 02:51
Listview控件获取当前行的行号和主键,1, 获取当前行的行号: int index = ((ListViewDataItem)e.Item).DisplayIndex;

2,获取当前行的主键: int id = Convert.ToInt32(ListView1.DataKeys[index].value);

protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
//获取当前行号;

int index = ((ListViewDataItem)e.Item).DisplayIndex;

//获取当前行号的主键;

int id = Convert.ToInt32(ListView1.DataKeys[index].Value);

//在Aspx页中添加一个按钮,CommandName为IncSeqNo

if (e.CommandName == "IncSeqNo")
{
//获取DataSet

T_FirendLinkTableAdapter adapter = new T_FirendLinkTableAdapter();

//更新字段;

adapter.UpdateQuery(id);

//重新绑定;

ListView1.DataBind();
}
}

原创粉丝点击