I have a DataTable object in C#, I pass the object to my aspx class in JavaScript like below. In JavaScript, I have a loop over the pages of a PowerBI report. All I need to do is to compare if the PageLists (from c#) includes page.DisplayName and do some process based on that. See the code below:
C#:
DataTable PagesList = null; //(this is globally defined)
...
protected void Page_Load(object sender, EventArgs e)
{
PagesList = sql.QueryDataTable(String.Format("select PageLabel, DefaultPage from myTable where ReportID = '{0}';",ReportID));
}
JavaScript:
<script>
var pageslist = "<%=PagesList%>";
alert(pageslist); //This pops up: "Table"
report.getPages().then(function (pages) {
var allpages = ''
pages.forEach(function(page) {
if(pageslist.includes(page.displayName) > -1) //this is not working properly
{
allpages = allpages+'<button type="button" onclick=setPage(\''+page.name+'\')>' + page.displayName+'</button>';
}
});
...
...
Here, it is not working as I expected, if part always returns false. What is the best way for this case to check if pageslist include page.displayName or not? How can I receive the items of the pageslist? Any help would be appreciated.