I have look all over the internet to see if someone has written code that converts the enumerable list in C# and return you a html table so that you can directly display it on UI. No luck. Here is what I have got I hope it helps someone. This code is test
Code Snippet
- public string GetAssociationValues()
- {
- IEnumerable<string> results = _omniService.GetAllAssociations();
- // format a list into table of check boxes.
- var sbTable = new StringBuilder();
- var sbRows = new StringBuilder();
- var sbColumns = new StringBuilder();
- int counter = 0;
- foreach (string result in results)
- {
- sbColumns.AppendFormat("<td><input type='checkbox' name='ImproveResultsAssociation' value='{0}' id='{0}'><span class='resAssociationText'>{0}</span></td>", result);
- counter++;
- // change the 2 to what ever number of columns you want to display the text.
- if (counter % 2 == 0)
- {
- sbRows.Append("<tr>" + sbColumns.ToString() + "</tr>");
- sbColumns.Clear();
- }
- }
- // last check if we are missing anything.
- if (sbColumns.Length>0)
- {
- sbRows.Append("<tr>" + sbColumns.ToString() + "</tr>");
- }
- sbTable.Append("<table>" + sbRows.ToString() + "</table>");
- return sbTable.ToString();
- }
No comments:
Post a Comment