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

            
if (e.CommandName == "IncSeqNo") //在Aspx页中添加一个按钮,CommandName为IncSeqNo
            {
                
//获取DataSet
                T_FirendLinkTableAdapter adapter = new T_FirendLinkTableAdapter();
                
//更新字段;
                adapter.UpdateQuery(id);
                
//重新绑定;
                ListView1.DataBind();
            }
        }

 

posted @ 2011-05-12 11:53  ゞ追忆o0ゞ  阅读(445)  评论(0编辑  收藏  举报