views:

50

answers:

1

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?

+1  A: 

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.

NYSystemsAnalyst
Thanks for that i new it would be something simple, But as always its knowning what that simple thing is..
TheAlbear