Having issue calling value from grid item control

1 Answer 51 Views
Grid
cest
Top achievements
Rank 1
Iron
cest asked on 16 Jul 2024, 12:51 PM

I am having issues calling the asset_SN value from a grid that does have a value (see picture) and feel my syntax is wrong as it states there isnt an object and when I look at portion of file output it is blank in the debugger (attached error code).

Frontend:
<telerik:RadGrid ID="RadGrid" runat="server" RenderMode="Auto" AllowPaging="True"  OnItemDataBound="RadGrid_ItemDataBound" OnNeedDataSource="RadGrid_NeedDataSource" 
    OnItemCommand="RadGrid_ItemCommand" OnItemCreated="RadGrid_ItemCreated" OnDeleteCommand="RadGrid_ItemDeleted" AllowSorting="true" AllowFilteringByColumn="true" 
    FilterType="HeaderContext" EnableHeaderContextMenu="True" EnableHeaderContextFilterMenu="True">   



<telerik:GridBoundColumn DataField="asset_SN" FilterControlAltText="Filter asset_SN column" HeaderText="Serial Number" SortExpression="asset_SN" UniqueName="asset_SN"></telerik:GridBoundColumn>


Backend: 
Dim assetSN As String = TryCast(editedItem.FindControl("asset_SN"), TextBox).Text

Error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

TryCast(..., System.Web.UI.WebControls.TextBox) returned Nothing.


1 Answer, 1 is accepted

Sort by
1
Vasko
Telerik team
answered on 19 Jul 2024, 06:24 AM

Hello Christopher,

The reason you're getting null is because of the TextBox typecasting. Since this is the regular EditForms item (and not a template), FindControl will not work (it works only when templates are involved).

You can check the Accessing Controls in Edit/Insert Mode to see how to get the built-in controls of an edit item.

Regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
Grid
Asked by
cest
Top achievements
Rank 1
Iron
Answers by
Vasko
Telerik team
Share this question
or