Hello, I rarely get a response on these forums, but i'm at the end of the line here...
I have a "simple" problem. I am currently using the web hierarchical data grid to display some schedule information. Each row contains 0 to many assignments. I simply want each assignment to be on a new line in the cell.
I was able to do this before by using the "<BR>" tag in the string that filled the cell, but that was with the UltraWebGrid and doesn't appear to be working in this one. The entire grid is populated with an IEnumerable object and the properties within that object, no bands/columns are set in the .aspx page. It seems like this should be really simple, but I can't figure out how to get the grid to recognize line breaks in the cells. I also attempted to use Environment.NewLine, but that didn't work either.
Hi jasonwilczak,
I apologize if you've previously had difficulty getting a response. Efforts are being made to ensure all posts get answered by someone from Infragistics.As to your question here, it should be fairly simple to solve. If you have defined your columns FormattedGridFields (in 11.1 and above) (which include BoundDataField and UnboundField) have a property called EnableMultiLine. This is false by default. But when it is set to true, it will convert any '\n' characters in the string into <br> on the server before sending the html down. Another option (and espically if you have 10.3 or below) would be to set HtmlEncode to false on the BoundDataField. This will allow your <BR> that you have in the string to go down as an actual <BR> instead of being encoded to show that text.I do see that you have nothing in the aspx, so if you're adding your columns dynamically, simply set those properties. If you're completely autogenerating, you'll need to access the column of a grid cell. like grid.GridView.Rows[0].Items[0].Column. Then typecase it and set the property.
regards,David Young
David,
No worries on the replies, i was just frustrated at the time of writing it. In any event, I am completely autogenerating the grid by an IEnumerable object datasource in the code behind. I am currently using the logic below to make it work. Essentially what I am doing is creating an object that uses ITemplate as it's interface. The object is a listbox which allows me to add rows into it. I then set the cells in the grid, that have "<BR>" tags into individual rows and then load the ITemplate object with those texts and values. I then assign the template to the cell. This is all being done the the InitializeRow event of the webhierarchical datagrid. I attempted the multi line property that you mentioned, as you can see commented out below, but it didn't work for me. Below is the InitializeRow event, then the custom ITemplate object and finally my grid aspx:
-----------WEB HIERARCHICAL DATA GRID INITIALIZE ROW EVENT CODE---------------
protected
void whdgSchedule_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
{
List<string> _hidden = ceScheduleUtility.ceScheduleHiddenProperties();
foreach (string s in _hidden)
if (e.Row.Items.FindItemByKey(s) != null)
e.Row.Items.FindItemByKey(s).Column.Hidden =
true;
}
if(e.Row.Items.FindItemByKey("Tooltip") != null)
for(int i = 0;i < e.Row.Items.Count;i++)
e.Row.Items[i].Tooltip = e.Row.Items.FindItemByKey(
"Tooltip").Text.Replace(":::", Environment.NewLine);
if (e.Row.Items[i].Text.Contains("<BR>"))
//((BoundDataField)e.Row.Items[i].Column).EnableMultiline = true;
List<string> _text = new List<string>();
string[] split = e.Row.Items[i].Text.Split(new string[] { "<BR>" }, StringSplitOptions.RemoveEmptyEntries);
_text.AddRange(split);
e.Row.Items[i].Template =
new CustomItemTemplate(_text, _text);
e.Row.Items[i].Column.Width =
new Unit(160, UnitType.Pixel);
-----------CUSTOM ITEMPLATE OBJECT CODE---------------
public class CustomItemTemplate : ITemplate
_count = 0;
_texts =
>(cTexts);
_values =
>(cValues);
else
>();
_count = (_texts.Count >= _values.Count ? _values.Count : _texts.Count);
#region
ITemplate Members
public void InstantiateIn(Control container)
edit.CssClass =
;
edit.Height =
.Pixel);
edit.Width =
edit.Items.Add(
(_texts[i], _values[i]));
container.Controls.Add(edit);
#endregion
-----------WEB HIERARCHICAL DATA GRID .ASPX CODE---------------
<
ig:WebHierarchicalDataGrid ID="whdgSchedule" runat="server" Height="500px"
Hello jasonwilczak,
Thank you for the update. Looking at your InitializeRow I have noticed a few things. First it appears that you are setting the <BR> into the row have you using the newline escape sequence ‘\n’ with the EnableMultiline property. Or have you tried using the HtmlEncode property set to false with the <BR>?
Please let know if you have any questions concerning this matter.
Sincerely,Mike P.Developer Support EngineerInfragistics, Inc.www.infragistics.com
I am following up to see if the information provided has resolved this matter.
Please let me know if I may be of further assistance with this matter.
Unfortunately, none of the settings seem to be working correctly for me that you suggested. However, converting the cell into a listbox and repopping the data on InitializeRow (the method I laid out above) is serving me fine for now. If you would like to close this issue out, you can.