0

Currently I have a dropdownlist in a asp:repeater. The dropdownlist gots two different events.

DataBinding and SelectedIndexChanged. But the SelectedIndexChanged just won't trigger not matter what.

Here's my ASP code:

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Repeater runat="server" ID="_repArticles">
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <img width="130" height="100" src='<%# Eval("ImageFilePath") %>' /> 
                                </td>
                                <td>
                                    <%# Eval("Price") %>
                                </td>
                                <td>
                                    <asp:DropDownList AutoPostBack="true" runat="server" ID="_ddlQuantity" OnDataBinding="_ddlQuantity_DataBinding" OnSelectedIndexChanged="_ddlQuantity_SelectedIndexChanged"></asp:DropDownList>
                                </td>
                                <td>
                                    <%# Eval("TotalPrice") %>
                                </td>
                                <td>
                                    <asp:LinkButton runat="server" ID="_btnRemove" OnClick="_btnRemove_Click" CssClass="close" ToolTip='<%$ Resources: Resource, Remove %>' CommandArgument='<%# Eval("ProductId") %>' ForeColor="Transparent" BackColor="Transparent"></asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </ContentTemplate>
            </asp:UpdatePanel>

And here's my C# code:

protected void _ddlQuantity_DataBinding(object sender, EventArgs e)
    {
        var ddl = sender as DropDownList;

        for (int i = 1; i < Convert.ToInt32(Eval("Stock")); i++)
            ddl.Items.Add(new ListItem(i.ToString(), i.ToString()));

        ddl.SelectedValue = Eval("Quantity").ToString();
    }

    protected void _ddlQuantity_SelectedIndexChanged(object sender, EventArgs e)
    {
        var ddl = sender as DropDownList;

        this.MasterPage.UpdateCartItem(Convert.ToInt32(Eval("ProductId")), Convert.ToInt32(ddl.SelectedValue));

        ddl.SelectedValue = Eval("Quantity").ToString();
    }

I start to think that you can't use both of these events, does anyone know what I am doing wrong?

Rick
  • 79
  • 1
  • 8

3 Answers3

0

You can try changing

UpdateMode="Always" 

from

UpdateMode="Conditional"
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
0

Well I got the solution, and it's a facepalm moment. I rebinded the repeater on the page load, forgot to set the "if (!IsPostBack)" around it.

Rick
  • 79
  • 1
  • 8
0

Put Triggers in UpdatePanel and then try

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Repeater runat="server" ID="_repArticles">
                    <ItemTemplate>
                        <tr>
                            <td>
                                <img width="130" height="100" src='<%# Eval("ImageFilePath") %>' /> 
                            </td>
                            <td>
                                <%# Eval("Price") %>
                            </td>
                            <td>
                                <asp:DropDownList AutoPostBack="true" runat="server" ID="_ddlQuantity" OnDataBinding="_ddlQuantity_DataBinding" OnSelectedIndexChanged="_ddlQuantity_SelectedIndexChanged"></asp:DropDownList>
                            </td>
                            <td>
                                <%# Eval("TotalPrice") %>
                            </td>
                            <td>
                                <asp:LinkButton runat="server" ID="_btnRemove" OnClick="_btnRemove_Click" CssClass="close" ToolTip='<%$ Resources: Resource, Remove %>' CommandArgument='<%# Eval("ProductId") %>' ForeColor="Transparent" BackColor="Transparent"></asp:LinkButton>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </ContentTemplate>
<Triggers>
            <asp:PostBackTrigger ControlID="_ddlQuantity" />
        </Triggers>
        </asp:UpdatePanel>
user2021740
  • 174
  • 2
  • 11