Repeater的ItemCommand事件

  <table cellpadding="0" cellspacing="0" width="100%" border="0">
                        <asp:Repeater ID="RptContact" runat="server" OnItemDataBound="RptContact_ItemDataBound" OnItemCommand="RptContact_ItemCommand">
                            <ItemTemplate>
                                <tr style="padding-top:10px">
                                    <td colspan="3">
                                        <table cellpadding="0" cellspacing="0" width="100%">
                                            <tr style="background-color:#efefef">
                                                <td align="left"><asp:Image ID="ContManPic" runat="server" /><asp:HyperLink ID="HypContName" runat="server" Font-Size="12px"></asp:HyperLink></td>
                                                <td align="left"><asp:Label runat="server" Font-Size="12px" ID="lblBaseInfo"></asp:Label></td>
                                                <td align="right">
                                                    <asp:LinkButton ID="lbtnDele" runat="server" Font-Size="12px" Text = "删除"></asp:LinkButton>&nbsp;&nbsp;&nbsp;&nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="left">地&nbsp;&nbsp;&nbsp;&nbsp;址:
                                    <asp:Label ID="lblAddress" runat="server" Font-Size="12px"></asp:Label>
                                    <td align="left">邮政编码:
                                    <asp:Label runat="server" ID="lblPost" Font-Size="12px"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td align="left">办公电话:
                                    <asp:Label runat="server" ID="lblOffTel" Font-Size="12px"></asp:Label></td>
                                    <td align="left">家庭电话:
                                    <asp:Label runat="server" ID="lblFamTel" Font-Size="12px"></asp:Label></td>
                                    <td align="left">移动电话:
                                    <asp:Label runat="server" ID="lblMobile" Font-Size="12px"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td align="left">寻&nbsp;呼&nbsp;机:
                                    <asp:Label runat="server" ID="lblPager" Font-Size="12px"></asp:Label></td>
                                    <td align="left">传&nbsp;&nbsp;&nbsp;&nbsp;真:
                                    <asp:Label runat="server" ID="lblFax" Font-Size="12px"></asp:Label></td>
                                    <td align="left">电子邮件:
                                    <asp:Label runat="server" ID="lblEmail" Font-Size="12px"></asp:Label></td>
                                </tr>
                                 <tr>
                                    <td colspan="3" align="left">网页地址:
                                    <asp:HyperLink ID="HypWebUrl" Target="_blank" Font-Size="12px" runat="server"></asp:HyperLink></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                           
                    </table>



   #region RptContact_ItemDataBound
    protected void RptContact_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            //联系人
            ((HyperLink)e.Item.FindControl("HypContName")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Name").ToString();
            ((HyperLink)e.Item.FindControl("HypContName")).NavigateUrl = "ContMan_Edit.aspx?Edit=Update&&ContID="
                + DataBinder.Eval(e.Item.DataItem, "Cont_ID").ToString();
            //联系人基本信息
            ((Label)e.Item.FindControl("lblBaseInfo")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Unit").ToString() + " " +
                DataBinder.Eval(e.Item.DataItem, "Cont_DepartMent").ToString() + " " +
                DataBinder.Eval(e.Item.DataItem, "Cont_Position").ToString();
            //联系地址
            ((Label)e.Item.FindControl("lblAddress")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Country").ToString() + " "
                + DataBinder.Eval(e.Item.DataItem, "Cont_Province").ToString() + " " + DataBinder.Eval(e.Item.DataItem, "Cont_City").ToString()
            + " " + DataBinder.Eval(e.Item.DataItem, "Cont_Street").ToString();
            //邮政编码
            ((Label)e.Item.FindControl("lblPost")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Post").ToString();
            //办公电话
            ((Label)e.Item.FindControl("lblOffTel")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_OffTel").ToString();
            //家庭电话
            ((Label)e.Item.FindControl("lblFamTel")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_FamTel").ToString();
            //移动电话
            ((Label)e.Item.FindControl("lblMobile")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Mobile").ToString();
            //寻呼机
            ((Label)e.Item.FindControl("lblPager")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Pager").ToString();
            //传真机
            ((Label)e.Item.FindControl("lblFax")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Fax").ToString();
            //电子邮件
            ((Label)e.Item.FindControl("lblEmail")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_Email1").ToString();
            //网页
            ((HyperLink)e.Item.FindControl("HypWebUrl")).Text = DataBinder.Eval(e.Item.DataItem, "Cont_WebUrl").ToString();
            ((HyperLink)e.Item.FindControl("HypWebUrl")).NavigateUrl = DataBinder.Eval(e.Item.DataItem, "Cont_WebUrl").ToString();

            LinkButton lbtnDele = (LinkButton)e.Item.FindControl("lbtnDele");

            lbtnDele.OnClientClick = "javascript:return confirm('您确定要删除该项么?')";
            lbtnDele.CommandName = "Delete";
            lbtnDele.CommandArgument = DataBinder.Eval(e.Item.DataItem, "Cont_ID").ToString();

        }
    }



    #region RptContact_ItemCommand
    protected void RptContact_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            long ContID = Convert.ToInt64(e.CommandArgument.ToString()) ;
            DeleteContact(ContID);
            DataBindContact();
        }
    }
    #endregion

原文地址:https://www.cnblogs.com/VirtualMJ/p/669613.html