asp:Repeater 添加button 事件
<ItemTemplate>
<asp:LinkButton ID="btnDisable" runat="server" CssClass='btn btn-sm btn-icon btn-danger' title="刪除"
CommandName="btnDisable" CommandArgument='<%# Eval("newsid")%>' OnClientClick="return confirm('刪除的案例無法恢復,確定刪除嗎?');"
><i class="glyphicon glyphicon-trash"></i></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
cs:
protected void itemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "btnDisable" )
{
int ID = int.Parse(e.CommandArgument.ToString());
}
}
//限制按鈕顯示
protected void repnewlsit_ItemDataBound
{
System.Data.DataRowView dr = (System.Data.DataRowView)e.Item.DataItem;
LinkButton btnDisable = (LinkButton)e.Item.FindControl("btnDisable");
LinkButton btnNoDisable = (LinkButton)e.Item.FindControl("btnNoDisable");
if (dr["lzf"].ToString().Trim() == "1")
{ btnDisable.Visible = true;
btnNoDisable.Visible = false;
}
else
{
btnDisable.Visible = false;
btnNoDisable.Visible = true;
}
}
asp:Repeater 添加button 事件