2010-05-27 6 views
1

리터럴, 드롭 다운 목록 및 버튼이있는 리피터가 있습니다.드롭 다운 목록이있는 리피터 내부 버튼

<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") 
      { 

      } 
     } 

버튼을 클릭 데리러해야 주어진 버튼 클릭으로, 텍스트 상자와 그 옆에있는 드롭 다운 목록에서 올바른 정보를 가져올 수 있습니까?

답변

1

RepeaterCommandEventArgs에는 단추 클릭이 발생한 특정 항목 (명령을 시작한 항목)을 참조하는 데 사용할 수있는 "Item"속성이 있습니다. 그런 다음 동일한 FindControl 메서드를 사용하여 컨트롤에서 데이터를 가져올 수 있습니다.

제공된 샘플 코드를 기반으로 CommandArgument 속성을 사용하여 제품 ID를 가져올 수 있습니다. 이것은 컨트롤에서 수집 된 데이터와 함께 주문을 생성 할 수있게 해줍니다.

+0

새로운 것을 고맙습니다. 뭔가 간단 할 것입니다. 그러나 언제나 그 단순한 것이 무엇인지를 아는 것입니다. – TheAlbear

관련 문제