API Questions on Kentico API.
Version 6.x > API > I'm having trouble with a custom transformation function View modes: 
User avatar
Member
Member
stephen.turley-terradon - 5/23/2012 8:44:24 AM
   
I'm having trouble with a custom transformation function
This is my transformation function call:

<p><%# MyFunctions.getDocumentCategory(Eval("DocumentID"))%></p>


This is the function:

 public static string getDocumentCategory(int documentID)
{

string category;

StringBuilder sb = new StringBuilder();
// Get document categories
var ds = CategoryInfoProvider.GetDocumentCategories(documentID, "CategoryEnabled = 1", null);
// Check whether exists at least one category
if (!DataHelper.DataSourceIsEmpty(ds))
{

// Loop thru all categories
foreach (DataRow dr in ds.Tables[0].Rows)
{
sb.Append(Convert.ToString(dr["CategoryDisplayName"]) + ",");
}
}
string content = sb.ToString();

category = content.Split(',')[0];

return category;
}
}


This is the error:

MyFunctions.getDocumentCategory(int) has some invalid arguments.


I've tried an alternate form of the function that accepts strings rather than ints but it throws the same error. I've verified that the `Eval("DocumentID")` works correctly when placed by itself. Any ideas?

User avatar
Member
Member
stephen.turley-terradon - 5/23/2012 9:16:56 AM
   
RE:I'm having trouble with a custom transformation function
Figured it out from StackOverflow. I had to make the method accept an object rather than an int then convert it to an int.