带下拉列表的中继器内的按钮
我有一个带有文字、下拉列表和按钮的中继器。
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.