Conversion from type 'DataRowView' to type 'String' is not valid

Simflex 301 Reputation points
2023-04-03T20:13:43.3366667+00:00

I have looked at some helpful tips generated based on Title but none has helped with the issue that I am having. When we run the code below, we keep getting error: Conversion from type 'DataRowView' to type 'String' is not valid I am lost as to what to try to fix this problem. Any ideas?

        Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
            If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
                'Find the DropDownList in the Repeater Item.
                Dim PurchaseDate As String = (TryCast(e.Item.FindControl("PurchaseDate"), TextBox)).Text
                Dim hfAsset As HiddenField = (TryCast(e.Item.FindControl("hfAsset"), HiddenField))

                Dim ddlAsset As DropDownList = (TryCast(e.Item.FindControl("ddlAsset"), DropDownList))
                ddlAsset.DataSource = GetData("SELECT DISTINCT AssetID, Asset FROM AssetTable")
                ddlAsset.DataTextField = "Asset"
                ddlAsset.DataValueField = "AssetID"
                ddlAsset.DataBind()
                ddlAsset.ClearSelection()
                If ddlAsset.Items.FindByText(hfAsset.Value) IsNot Nothing Then
                    ddlAsset.Items.FindByText(hfAsset.Value).Selected = True
                End If
            End If
        End Sub
        
	       <HeaderTemplate>
		    <table border="1" style="background-color:White; width:90%; border-color:lavender; border-collapse:collapse;">
		    <tr>
			<th style="text-align:left;">
			    Assets </th>
			<th style="text-align:left;">
			    Purchase  Date </th>
                    </tr>
                    </HeaderTemplate>
	            <ItemTemplate>
		    <tr>
		    <td>
	             <asp:DropDownList ID="ddlToiletGPF" class="ChangeWidth" AppendDataBoundItems="true" runat="server" AutoPostBack="true" >
                      <asp:ListItem Text="Select" selected="True" Value="" />
		        </asp:DropDownList>
                     <asp:HiddenField ID="hfAsset" runat="server" Value='<%# Eval(Container.DataItem, "Asset") %>' />
		    </td>
                    <td>
			<asp:TextBox ID="PurchaseDate" style="width:200px" Text='<%# DataBinder.Eval(Container.DataItem, "PurchaseDate") %>' DataFormatString="{0:MM/dd/yyyy}" runat="server"></asp:TextBox><ajax:CalendarExtender ID="pruchaseDte" runat="server" TargetControlID="PurchaseDate" Format="MM/dd/yyyy" ViewStateMode="Enabled" />
		    </td>
    	          </tr>
	        </ItemTemplate>

Error is on this line:

<asp:HiddenField ID="hfAsset" runat="server" Value='<%# Eval(Container.DataItem, "Asset") %>' />

Thanks in advance for your assistance

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,605 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 26,166 Reputation points
    2023-04-03T20:36:47.39+00:00

    Shouldn't you use DataBinder.Eval like your other binding logic?

    <asp:HiddenField ID="hfAsset" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Asset") %>' /> 
    

    Or

    <asp:HiddenField ID="hfAsset" runat="server" Value='<%# Eval("Asset") %>' /> 
    

    Reference documentation. DataBinder.Eval Method


0 additional answers

Sort by: Most helpful