1. 程式人生 > >asp:Repeater 添加button 事件

asp:Repeater 添加button 事件

parse else argument nat icon eval news disable eva

<asp:Repeater runat="server" ID="repnewlsit" OnItemCommand="itemCommand" OnItemDataBound="repnewlsit_ItemDataBound">

<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

(object sender, RepeaterItemEventArgs e)

{

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 事件