Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I came across this error recently and I don't understand what to do

There is a hidden filed

<asp:hiddenfield id="hfResourceID" runat="server" value="0">

and I am collecting this value like

long resourceId = Convert.ToInt64(hfResourceID.Value); and the error comes here

private void searchGlobal()
{
enResourceType resourceType =
Request.QueryString["ResourceGroupType"] != string.Empty
? (enResourceType)Enum.ToObject(typeof(enResourceType), Convert.ToInt16(Request.QueryString["ResourceGroupType"]))
: enResourceType.Both;

if (resourceType == enResourceType.Network &&
Request.QueryString["From"] == "GlobalResourceGroupRequest")
plhCreateNewNetwork.Visible = true;

string requestID = (Request.QueryString["RequestID"] != null) ? (string)Request.QueryString["RequestID"] : "0";

grdResources.DataSourceID = "ResourceDataSource";

ResourceDataSource.SelectMethod = "SearchGlobal";
ResourceDataSource.SelectParameters.Clear();
ResourceDataSource.SelectParameters.Add("name", txtName.Text);
ResourceDataSource.SelectParameters.Add("requestID", requestID);
ResourceDataSource.SelectParameters.Add("resourceType", resourceType.ToString());
ResourceDataSource.SelectParameters.Add("folioID", folioID.Text);

grdResources.DataBind();
}

This line throws error grdResources.DataBind();

I don't understand what to do here? Please help

What I have tried:

tried to change Convert.ToInt64 to Convert.ToInt16 but didn't work.
Posted
Updated 8-Jan-22 23:02pm

1 solution

Look at the affected line of code, and at the error message:
Undefined is not a valid value for int64

C#
long resourceId = Convert.ToInt64(hfResourceID.Value);

What it's saying is that there is no value in hfResourceID.Value, so it can;t be made into a long integer value.

If you use the debugger to view the content of hfResourceID.Value you will probably get a null value because either your code or the user has not set it to anything. Probably, this means that there is a NULL value in your database that you aren't expecting, and you need to sort out your data integrity first - but we have no access to any of your data so we can;t even check, much less fix it!

If that isn't the case, then either give it a default value that will make sense to the rest of your code, or check for invalid values and report an error instead of continuing as if it was correct.
 
Share this answer
 
Comments
Member 14362033 9-Jan-22 5:14am    
Hello, yes you are correct but I assigned hfResourceID like this

<asp:hiddenfield id="hfResourceID" runat="server" value="0"> is it not working?
OriginalGriff 9-Jan-22 6:17am    
So you need to use the debugger to look at what the value is now, and start to work out where that came from. We can't do that for you - we can't run your code with your data - so you need to start doing it.
Richard Deeming 10-Jan-22 5:53am    
If the field value is literally the string "undefined", then there's probably some Javascript code which is updating the field value, and that Javascript code has an error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900