asp:Repeater 添加button 事件

 <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;

        }

    }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章