我在gridview中有一个按钮和一个无界标签(用于库存量级别标记)。(其他列有界)。当我单击按钮时,我希望显示“已点击的行”的标签:根据情况有库存或无货。但是现在ALL ROWS的All标签都显示相同的东西。
单击按钮事件中的代码将检查数量(条件)级别,并且工作正常。我还能够从RowDataBound的gridview中找到标签,并基于数量条件设置text属性,但是无法让此标签和text属性仅在单击的行中显示。
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.UpdateQtyIncreament(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.UpdateQtyIncreament(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="btnIncreameant" runat="server" CausesValidation="false" CommandName="Increament"
Text="+" OnClick ="btninc_Click" Font-Bold="True" style="background-color:#fff; border :solid 1px #ccc" />
</ItemTemplate>
这是此刻购物车的样子。