asp.net - 如何从同一网格视图中的按钮的单击事件中设置 GridView 中标签的文本值
问题描述
我在 gridview 中有一个按钮和一个无界标签(用于库存数量级别标志)。(其他列有界)。当我单击按钮时,我希望 CLICKED ROW 的标签显示:根据条件有货或缺货。但是现在所有行的所有标签都显示相同的东西。
按钮单击事件中的代码检查数量(条件)级别并且工作正常。我还能够从 RowDataBound 中的 gridview 中找到标签并根据数量条件设置文本属性,但无法让该标签和文本属性仅显示在单击的行中。
Private Sub CartGrid_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles CartGrid.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
If ProdQtyInStock = 0 Then
Dim lblCartQtyMsg As Label = CType(e.Row.FindControl("lblCartQtyMsg"), Label)
lblCartQtyMsg.Text = "Out of Stock"
End If
End If
End Sub
我希望标签只显示在单击按钮的行上。这是按钮单击事件的代码:
Protected Sub btninc_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim PlusButton As Button = DirectCast(sender, Button)
Dim Row As GridViewRow = DirectCast(PlusButton.Parent.Parent, GridViewRow)
Dim productid As String = CartGrid.DataKeys(Row.RowIndex).Value.ToString
Dim lblcartSize As Label = CType(Row.FindControl("lblcartSize"), Label)
Dim lblcartcolor As Label = CType(Row.FindControl("lblcartColor"), Label)
Dim lblCartQty As Label = CType(Row.FindControl("LblCartQty"), Label)
Dim cartQty As String
If lblcartSize.Text.ToString = "NIL" And lblcartcolor.Text.ToString = "NIL" Then
Dim colorid, sizeid As Integer
sizeid = 1
colorid = 1
ProdQtyInStock = ShoppingCart.StockQtyChecker(productid, sizeid, colorid)
If ProdQtyInStock = 1 Then
ShoppingCart.UpdateQtyIncrement(productid, sizeid, colorid)
ElseIf ProdQtyInStock = 0 Then
' show lblCartQtyMsg.Text = "Out of Stock"
End If
' bindShoppingCart()
ReCalculateShippingCost()
Else
Dim colorid, sizeid As Integer
colorid = ShoppingCart.GetColorIDforProdCartDelete(productid, lblcartcolor.Text.ToString).colorid
sizeid = ShoppingCart.GetSizeIDforProdCartDelete(productid, lblcartSize.Text.ToString).sizeid
ProdQtyInStock = ShoppingCart.StockQtyChecker(productid, sizeid, colorid)
If ProdQtyInStock = 1 Then
ShoppingCart.UpdateQtyIncrement(productid, sizeid, colorid)
ElseIf ProdQtyInStock = 0 Then
'at show lblCartQtyMsg.Text = "Out of Stock"
End If
'' bindShoppingCart()
ReCalculateShippingCost()
End If
cartQty = lblCartQty.Text
End Sub
这是按钮的html:
<ItemTemplate>
<asp:Button ID="btnIncrement" runat="server" CausesValidation="false" CommandName="Increment"
Text="+" OnClick ="btninc_Click" Font-Bold="True" style="background-color:#fff; border :solid 1px #ccc" />
</ItemTemplate>
这是购物车目前的样子。
解决方案
推荐阅读
- node.js - Nodejs 将图像数据转换回实际图像
- javascript - 当包括胜利图时,反应原生滑块变得迟钝并且状态值变化最近反映
- java - NullPointerException 使用 Java 中的库从 GCS 读取文件
- python - 是否可以使用 bs4 将新实例添加到一行?
- javascript - 在较小的可见容器内移动大图像
- .net-core - 尝试使用所有设置了 elementFormDefault=“qualified” 的 xsd 的 wsdl,但生成的请求仍然没有子前缀
- bash - bash 在尝试执行时声称可执行文件不存在,但它确实存在
- c# - 如何根据类别用以前的非空值填充空值
- ruby-on-rails - 谷歌 SPA oauth + JWT + Rails
- json - 从 Teams 中的 action.submit 发送 POST