0

I have tried post on same subject but didn't work. it didn't actually fire event

What I want

I want to fire ItemCommand event when some one click on repeater.

Issue

The ItemCommand is not fired.

EnableViewState=true

Here is by code:

Html:

<table>
              <asp:Repeater ID="outerRepeater" runat="server"
                    OnItemDataBound="outer_OnitemdataBound" 
                  onitemcommand="outerRepeater_ItemCommand">
                <ItemTemplate>
                <asp:Repeater ID="Rgallery" runat="server">
                    <ItemTemplate>
                      <%# (Container.ItemIndex + 4) % 4 == 0 ? "<tr>" : string.Empty %>  
                        <td>
                            <img src="<%# Eval("ImgPath") %>" style="height:300px; width:300px;" alt="" />
                                <div class="caption">
                         <h3><%# Eval("Type") %></h3>
                         <p><b><%# Eval("SubType") %></b></p>
                         <p{font-family: "Comic Sans MS", cursive, sans-serif; font-size: 25px}>Price:<i class="fa fa-inr fa-fw"><%# Eval("Price") %></i></p>
                         <p><asp:Button ID="btnBuy" CommandName="Buy" CommandArgument="Add to Cart" class="btn btn-primary" Text='<%# DataBinder.Eval(Container.DataItem, "Price") %>' runat="server" />
                         </p>
                        </div>
                        </td>
                        <%# (Container.ItemIndex + 4) % 4 == 3 ? "</tr>" : string.Empty%>
                    </ItemTemplate>
                </asp:Repeater>
                </ItemTemplate>
              </asp:Repeater>
              <asp:Label ID="lblStatus" runat="server" ></asp:Label>
    </table>

and here is code behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dummy = new DataTable();
        dummy.Columns.Add();
        dummy.Rows.Add();
        rptMain.DataSource = dummy;
        rptMain.DataBind();
        outerRepeater.DataSource = dummy;
        outerRepeater.DataBind();
    }
    if (Page.IsPostBack)
    { return; }

}

protected void outerRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    // Here is a code I want to fire
}
protected void outer_OnitemdataBound(object sender, RepeaterItemEventArgs e)
{
    Repeater repeater = e.Item.FindControl("RGallery") as Repeater;
    repeater.DataSource = db.GetTable("SELECT `Did`, `Type`, `SubType`, `Gender`, `Price`, `ImgPath` FROM `designs` ORDER BY `Did` DESC");
    repeater.DataBind();
}

What i have tried so far

Method 1

I have put onItemCommand="rptthumbnail_ItemCommand" But i didn't worked.

Method 2 I have add handlar in OnInit() But i didn't worked too.

Can some please identify that what's the problem Please help me with this.....

4

1 回答 1

0

因为您的按钮是您的内部中继器的子级,所以它将触发该ItemCommand事件。将事件绑定向下移动到该转发器应该会为您修复它。

<asp:Repeater ID="outerRepeater" runat="server"
    OnItemDataBound="outer_OnitemdataBound">
    <ItemTemplate>
        <asp:Repeater ID="Rgallery" runat="server"
            OnItemCommand="Rgallery_ItemCommand">
protected void Rgallery_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    // Here is a code I want to fire
}
于 2015-11-28T20:01:44.063 回答