ItemCommand 事件
要在datalist 模版的项中的ImageButton中 捕获单击事件.vs2003中不支持直接写ImageButton_Click,用ItemCommand 事件 来实现.
ItemCommand 事件在单击 数据源 控件中的任一按钮时引发,并且在具有带自定义 CommandName 值的按钮控件时通常使用它。
CommandArgument(从 CommandEventArgs 继承) 获取命令的参数。
CommandName(从 CommandEventArgs 继承) 获取命令的名称。
CommandSource 获取命令源。
Item 获取 DataList(datagrid等同理) 控件中包含命令源的项。
<asp:DataList ID="dl_pro" runat="server">
<ItemTemplate>
<asp:LinkButton id=LinkButton1 runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"proname").ToString() %>' CommandName="Id" Width="111px">
<%# DataBinder.Eval(Container.DataItem,"proname").ToString() %>
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
private void dl_pro_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
//可通过 e 得到各个参数值
if(e.CommandName=="Id")
{
//Response.Redirect("pro.aspx?userid");
// Set the SelectedIndex property to select an item in the DataList.
// ItemsList.SelectedIndex = e.Item.ItemIndex;
// Rebind the data source to the DataList to refresh the control.
//ItemsList.DataSource = CreateDataSource();
//ItemsList.DataBind();
}
}