C# 通过 Repeater 中的 CommandArgument 传递文本框内容
<asp:Repeater ID="Cartridges" runat="server" onitemcommand="Cartridges_ItemCommand">
<ItemTemplate>
<p class="cartprice"><%#String.Format("{0:C}", Eval("Price"))%></p>
<hr class="hr4" />
<p class="cartqty">QTY <asp:TextBox ID="cartQty" Text="0" runat="server"></asp:TextBox> </p>
<div class="cartbuy2"><asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument=<%#Eval("cartID") %> Text="Buy"></asp:LinkButton></div>
</ItemTemplate>
</asp:Repeater>
如何在 CommandArgument 中传递文本框值?抱歉彻底迷失了...
<asp:Repeater ID="Cartridges" runat="server" onitemcommand="Cartridges_ItemCommand">
<ItemTemplate>
<p class="cartprice"><%#String.Format("{0:C}", Eval("Price"))%></p>
<hr class="hr4" />
<p class="cartqty">QTY <asp:TextBox ID="cartQty" Text="0" runat="server"></asp:TextBox> </p>
<div class="cartbuy2"><asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument=<%#Eval("cartID") %> Text="Buy"></asp:LinkButton></div>
</ItemTemplate>
</asp:Repeater>
How can I pass the textbox value within CommandArgument? Sorry totally lost...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过:
CommandArgument='<%#Eval("cartID") %>'
这与您的不同,因为它由单引号引起来,我想这是正确的语法。
Did you try:
CommandArgument='<%#Eval("cartID") %>'
this is different from yours as it is surrounded by a single quote, I guess this is the correct syntax.
使用 FindControl 获取中继器 Item 中的其他项目。例如:
Use FindControl to get other items in the repeater Item. For Example:
您需要将 cartId 绑定到 onItemDataBound 上的链接按钮,然后在 onItemCommand 上访问它,我已经为您修改了代码,请尝试一下
您的 onItemdatabound 应该如下所示
,然后您可以像这样访问 item 命令上的文本框
您还可以通过添加更多链接按钮并将它们绑定到正确的命令,然后在 on item 命令中访问它们,使用编辑/删除命令参数扩展您的代码
谢谢
you need to bind the cartId to the linkbutton onItemDataBound and then access it onItemCommand, I have modified code for you, give this a go
your onItemdatabound should look like this
and then you can access the text box on item command like this
You can also extend your code with edit/delete command arguments by adding more linkbuttons and binding them to the correct command and then accessing them in on item command
Thanks