我有一个中继器,它代表一个购物篮。这个购物篮有一个“更新数量”和一个“删除项目”按钮。
当您编辑数量并点击输入时,我将需要它来使用更新数量按钮(与现在使用删除项目按钮不同)。
在代码中,我尝试通过添加带有 DefaultButton 的“QuantityPanel”来解决这个问题,但这并没有解决我的问题!
有什么想法吗?
我的代码:
<asp:Repeater ID="ProductBasketRepeater" runat="server"
onitemcommand="ProductBasketRepeater_ItemCommand"
onitemdatabound="ProductBasketRepeater_ItemDataBound1">
<ItemTemplate>
<tr class="BasketEntryItem">
<td class="ImageCol">
<asp:Image ID="ProductImageBox" runat="server" Width="50" />
</td>
<td class="NameCol">
<asp:HyperLink ID="ProductNameHyperlink" runat="server"></asp:HyperLink>
</td>
<td class="PriceCol">
<asp:Label ID="PriceLabel" runat="server"></asp:Label>
</td>
<td class="QuanCol">
<asp:Panel ID="QuantityPanel" runat="server" DefaultButton="UpdateQuantityBtn">
<asp:TextBox ID="QuantityBox" runat="server" Width="30px"></asp:TextBox>
<asp:LinkButton ID="UpdateQuantityBtn" runat="server" Text="Opdater" CommandName="UpdateQuantity"></asp:LinkButton>
</asp:Panel>
</td>
<td class="TotalCol">
<asp:Label ID="TotalPriceLabel" runat="server"></asp:Label><br />
<asp:Button ID="DeleteProductBtn" runat="server" Text="Slet" CommandName="Delete" />
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
</asp:Repeater>
最佳答案
如果 jQuery 不可用,您可以使用简单的 JavaScript 来设置任何文本框的默认按钮:
JS代码:
function clickButton(e, buttonid){
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt){
if (evt.keyCode == 13){
bt.click();
return false;
}
}
}
ASPX 页面或任何简单的“输入”文本框:
<input name="TextBox1" type="text" id="TextBox1" onkeypress="return clickButton(event,'Button1')" />
代码开始于 C#:
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");
在转发器中应用此代码需要帮助吗?
关于c# - 带有文本框和按钮的 Repeater 中的 DefaultButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8718091/