带下拉列表的中继器内的按钮

发布于 2024-09-02 20:02:56 字数 1561 浏览 5 评论 0原文

我有一个带有文字、下拉列表和按钮的中继器。

  <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="rep_ItemDataBound" onitemcommand="Repeater1_ItemCommand">
        <ItemTemplate>
          <div class="buypanel">
        <ul>
            <li>Choose finish <asp:DropDownList ID="ddlFinish" runat="server"></asp:DropDownList></li>
            <li>Qty <asp:Literal ID="ltQty" runat="server"></asp:Literal></li>
            <li><asp:Button ID="butBuy" runat="server" Text="Button" /></li>
        </ul>
        </div>
    </ItemTemplate>
    </asp:Repeater>

我将所有信息绑定在后面的代码中,

 protected void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Products product = (Products) e.Item.DataItem;


               //Dropdownlist to be bound. 

                //Set Buy Button
                var butBuy = (Button) e.Item.FindControl("butBuy");
                butBuy.CommandName = "Buy";
                butBuy.CommandArgument = product.Id.ToString();

            }
        }

并且我有我的 itemcommand 在按钮单击上拾取

  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if(e.CommandName == "Buy")
            {

            }
        }

我不知道如何通过单击给定的按钮从文本框和下拉列表中拾取正确的信息一边呢?

I have a repeater with a literal, a dropdown list, and a button.

  <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="rep_ItemDataBound" onitemcommand="Repeater1_ItemCommand">
        <ItemTemplate>
          <div class="buypanel">
        <ul>
            <li>Choose finish <asp:DropDownList ID="ddlFinish" runat="server"></asp:DropDownList></li>
            <li>Qty <asp:Literal ID="ltQty" runat="server"></asp:Literal></li>
            <li><asp:Button ID="butBuy" runat="server" Text="Button" /></li>
        </ul>
        </div>
    </ItemTemplate>
    </asp:Repeater>

I am binding all the information in the code behind like

 protected void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Products product = (Products) e.Item.DataItem;


               //Dropdownlist to be bound. 

                //Set Buy Button
                var butBuy = (Button) e.Item.FindControl("butBuy");
                butBuy.CommandName = "Buy";
                butBuy.CommandArgument = product.Id.ToString();

            }
        }

and i have my itemcommand to pick up on the button click

  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if(e.CommandName == "Buy")
            {

            }
        }

I am not sure how, with a given button click, to pickup the right information from the text box and dropdown list which is along side it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞳孔里扚悲伤 2024-09-09 20:02:56

RepeaterCommandEventArgs 有一个“Item”属性,您可以使用该属性来引用发生按钮单击的特定项目(启动命令的项目)。然后,您可以使用相同的 FindControl 方法从控件中获取数据。

根据您提供的示例代码,您可以使用 CommandArgument 属性来获取产品 ID。这与从控件收集的数据相结合将允许您创建订单。

The RepeaterCommandEventArgs has an "Item" property that you can use to reference the specific item in which the button click occurred (the item that launched the command). Then, you can use the same FindControl method to get the data from the controls.

Based on the sample code you gave, you can use the CommandArgument property to get the product ID. This, in conjunction with the data gathered from the controls will allow you to create an order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文