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();
}
}