Findcontrol issue

Findcontrol issue

am 11.01.2008 21:05:27 von Me LK

I have a grid with an editable amount. Click update and the text box
appears and the number changes. It works fine here.

Private Sub grid_updatecommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grid.UpdateCommand

Dim intProductId As String = grid.DataKeys(e.Item.ItemIndex)
Dim quantity As String =
CType(e.Item.FindControl("quantityTextBox"), TextBox).Text

Try
ShoppingCart.UpdateProductQuantity(intProductId, quantity)
Catch ex As Exception
'If the update generates an error this is the place we
should warn the users
Finally
grid.EditItemIndex = -1
bindShoppingCart()

End Try
End Sub

But I need to add the size and color to the update since there may be
items with the same ID but different sizes or colors. So I changed my
code to this.

Private Sub grid_updatecommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grid.UpdateCommand
Dim intProductId As String = grid.DataKeys(e.Item.ItemIndex)
Dim quantity As String =
CType(e.Item.FindControl("quantityTextBox"), TextBox).Text


Dim Psize As String = CType(e.Item.FindControl("Psize"),
Label).Text
Dim color As String = CType(e.Item.FindControl("color"),
Label).Text

Try
ShoppingCart.UpdateProductQuantity(intProductId, quantity,
Psize, color)
Catch ex As Exception
'If the update generates an error this is the place we
should warn the users
Finally
grid.EditItemIndex = -1
bindShoppingCart()

End Try
End Sub

For some reason I get the dreaded
"Object reference not set to an instance of an object. "

at this line
Dim Psize As String = CType(e.Item.FindControl("Psize"),
Label).Text

I have my code as this

HorizontalAlign="Center">


ItemTemplate>
Is there something I am doing wrong with the syntax of findcontrol for
the Psize. The code is almost identicle to the quantity (which works)
except that it is a label.