jxbma
asked on
How do I pass an array of objects to my (code behind) accessor method in ASP.Net?
Hey Guys:
Hope y'all doing well.
I've got an ASP .Net/C# question
I've got the following accessor method on my base page code behind:
-------------------------- ---------- ---------- ---------- ---------- -
public static string RetrieveTimeStampFromAudit (AuditRecord[] auditHistory, string operationTypeStringToFind, string format)
{
//TODO Add implementation
}
I'd like to be able to call it from my ASP.Net page, more or less
in the following fashion:
-------------------------- ---------- ---------- ---------- ---------
Text='<%# RetrieveTimeStampFromAudit ("Foobar.A uditRecord ", "Created", "MM/dd/yyyy") %>'
I'm getting casting errors at page load time.
I’ve tried changing the Method definition to
Object
Object[]
and playing with the the actual call on the Asp .Net page.
Do you have any suggestions how to manipulate this cast/definition to work?
Thanks,
JB
Hope y'all doing well.
I've got an ASP .Net/C# question
I've got the following accessor method on my base page code behind:
--------------------------
public static string RetrieveTimeStampFromAudit
{
//TODO Add implementation
}
I'd like to be able to call it from my ASP.Net page, more or less
in the following fashion:
--------------------------
Text='<%# RetrieveTimeStampFromAudit
I'm getting casting errors at page load time.
I’ve tried changing the Method definition to
Object
Object[]
and playing with the the actual call on the Asp .Net page.
Do you have any suggestions how to manipulate this cast/definition to work?
Thanks,
JB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Final Comment : Change the first parameter of the method :
To an object of AuditRecord[] class like this one for example :
I think thats your issue..Its not able to cast the string "Foobar.AuditRecord" into an object of type AuditRecord[]
public static string RetrieveTimeStampFromAudit (AuditRecord[] auditHistory, string operationTypeStringToFind, string format)
{
//TODO Add implementation
}
To an object of AuditRecord[] class like this one for example :
AuditRecord[] obj = new AuditRecord[10];
string test = RetrieveTimeStampFromAudit(obj,"Created","MM/dd/yyyy");
I think thats your issue..Its not able to cast the string "Foobar.AuditRecord" into an object of type AuditRecord[]
Also, keep in mind you are using
Text='<%# RetrieveTimeStampFromAudit("Foobar.AuditRecord", "Created", "MM/dd/yyyy") %>'
to call your method. Depending on where that code appears in your asp.net page, this may not work. Using the # will only work inside of a databound control, otherwise you would use
Text='<%= RetrieveTimeStampFromAudit("Foobar.AuditRecord", "Created", "MM/dd/yyyy") %>'
. I'm just throwing this out there, but it doesn't sound like it would produce the error you are receiving.
I have a Solution for You Plz try this code :
Open in new window
One of the above declarations may definitely work for you.. See since the return type of this method is a string I think it would definitely be necessary to cast it to a string object.