Hi all,
Should need some help on this :
I have a Detailsview "ProductDetails"where some labels have custom formatting, i.e.:
<
asp:Label ID="absoluteMargin" runat="server" OnDataBinding="ProductDetails_DataBound"></asp:Label>
The formatting occurs when the data is bound. This is only used in the Itemtemplate created for the productinfo. The InsertTemplate should do no formatting because there isno data (yet). But it seems that de ProductsDetails Itemtemplate also reacts on the insert command.
I get the exception: "Object reference not set to an intance of an object" for the ProductDetails.DataItem.
The Productsdetails_Databound() should not fire when going to InsertTemplate. What should be the workarround for this? I understand that a NullException fireswhen there is no data to be bound.
I short : how can I make the Productsdetails_Databound() works only for the ItemTemplate of Productsdetails and fires no exceptions :-)
Protected Sub ProductDetails_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductDetails.DataBound
Try
Dim product As MFDatabaseDAL.PRODUCTSRow = CType(CType(ProductDetails.DataItem, System.Data.DataRowView).Row, MFDatabaseDAL.PRODUCTSRow)
Dim absMargin As Label = CType(ProductDetails.FindControl("absoluteMargin"), Label) '
'Do Some formatting
Catch ex As Exception
'do something
End Try
End Sub