数据绑定button,点击产生对应项事件


你这个按钮如果是在DataList1里面的
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
LinkButton lbtnDelete;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//删除确认
lbtnDelete = (LinkButton) e.Item.FindControl("lbtnDelete");;
lbtnDelete.Attributes.Add("onclick","return confirm('确定删除第" + (e.Item.ItemIndex + 1) + "项?');");
}
}
想到了很简单,问题就是没想到~


    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Show_Hidden")
        {
            Label txt = (Label)e.Item.FindControl("ProductNameLabel");

            if (ViewState["IsVisible"] != null && (bool)ViewState["IsVisible"])
            {
                txt.Visible = true;
                ViewState["IsVisible"] = false;
            }
            else
            {
                ViewState["IsVisible"] = true;
                txt.Visible = false;
            }
        }
    }

html
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="Show_Hidden" />


更多在这里
http://www.cnblogs.com/ilovejolly/archive/2006/12/15/593555.html

你可能感兴趣的:(button)