repeater linkbutton not firing

拥有回忆 提交于 2019-12-13 00:53:56

问题


I have a repeater and inside it a linkbutton, the repeater is bound to OnItemCommand but the event is not firing here is my code:

<asp:Repeater ID="rptList" runat="server" OnItemDataBound="rpt_OnItemDataBound" OnItemCommand="rptList_ItemCommand">
                <ItemTemplate>
                    <asp:LinkButton ID="lbName" Text='<%# Eval("Name") %>' runat="server" 
                        CommandArgument='<%# Eval("ID").ToString() %>' CommandName="NameClick">  
                    </asp:LinkButton><br />

                    <asp:Label ID="lblCreateDate" runat="server" Text='<%# Eval("CreateDate") %>' /><br />
                    <br />
                </ItemTemplate>
            </asp:Repeater>

here is the code behind:

protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "NameClick":
                    Guid id = (Guid)e.CommandArgument;

                    //do something
                    break;

                default:
                    break;
            }
        }

回答1:


As per Ram S comment you need to make sure you are not rebinding the repeater on postback (see this question Repeater's Item command event is not firing on linkbutton click)

You will also have a problem casting a Guid in that way - change this line of code

Guid id = (Guid)e.CommandArgument;

To this

Guid id = new Guid(e.CommandArgument.ToString());


来源:https://stackoverflow.com/questions/13136651/repeater-linkbutton-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!