.aspx文件里的datagrid中: <asp:ButtonColumn Text="添加信息" CommandName="Add"></asp:ButtonColumn> <asp:ButtonColumn Text="更新信息" CommandName="Update"></asp:ButtonColumn> 后台: Private Sub myDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles myDataGrid.ItemCommand If e.CommandName = "Add" Then ...... End If If e.CommandName = "update" Then ...... End If End Sub
? vb里就是用e.items.cells()
你想得到说点击的那一列的所有数据吗? ArrayList al=new ArrayList(); foreach (DataGridItem item in dg.items) { LinkButton linkBut=(LinkButton)item.FindControls(linkbutton); if (linkBUt!=null) { al.Add(value);//value就是你想要的数据,自己定义 }
就可以得到你要的列了
不用取第几列了
(LinkButton)e.Item.FinfControl("LinkButton的ID")中“LinkButton的ID”的数据如何取?怎么知道点击的是当前列
我做过一次是设置了每个列的排序字段名称,但是datagrid的allowsort设置为false ,这样就可以通过 e.item 的排序字段遍历dg中的列,找到匹配的项,就知道是哪一列了
<asp:ButtonColumn Text="添加信息" CommandName="Add"></asp:ButtonColumn>
<asp:ButtonColumn Text="更新信息" CommandName="Update"></asp:ButtonColumn>
后台:
Private Sub myDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles myDataGrid.ItemCommand
If e.CommandName = "Add" Then
......
End If
If e.CommandName = "update" Then
......
End If
End Sub
ArrayList al=new ArrayList();
foreach (DataGridItem item in dg.items)
{
LinkButton linkBut=(LinkButton)item.FindControls(linkbutton);
if (linkBUt!=null)
{
al.Add(value);//value就是你想要的数据,自己定义
}