I am new to Infragistics and I am having difficulty figuring out a solution for my problem. I have a WebDataGrid with 6 columns. The first column's data includes an ID number, Name of product, and a long description. My boss wants me to add a 2nd row to include the Product Namd and Description (which then will allow the first column to simply have an ID).
Can you have 2 rows for each DataRow in a WebDataGrid? The second row will not have a column name. I simply want to combine the current 6 columns and make it into one big column and add my description. Is this possible within WebDataGrid? Because this grid is in a modal I am limited on space and that is why we are going to two rows instead of one. If I can figure out how it can be done, I plan to have every other 2 rows highlighted so you can easily see which 2 rows are associated with each other.
Any help or tips for this issue would be greatly appreciated. Below are images showing what the grid looks like now and what I would like it to look like. Thanks again.
Hello,
In order to achieve the custom layout you are describing I would suggest using a custom ItemTemplate. This way you can arrange the data from the data item as it best suits your scenario.
First, create a CustomItemTemplate as follows:
private class CustomItemTemplate : ITemplate { public void InstantiateIn(Control container) { var dataItem = ((DataRowView)((TemplateContainer)container).DataItem); Label idLabel = new Label(); idLabel.Text = dataItem["ID"].ToString(); Label detailsLabel = new Label(); detailsLabel.Text = dataItem["Name"].ToString() + " " + dataItem["Description"].ToString(); container.Controls.Add(idLabel); container.Controls.Add(new LiteralControl("<br />")); container.Controls.Add(detailsLabel); } }
Then add a TemplateDataField whose item template is the one you've just created, and add it to the grid's Columns collection.
TemplateDataField field1 = new TemplateDataField(); field1.Key = "TemplateColumn1"; field1.Header.Text = "ID"; WebDataGrid1.Columns.Add(field1); field1.ItemTemplate = new CustomItemTemplate();
I am attaching a small sample application demonstrating this approach for your reference. Review it and let us know if you have any further questions on the matter.
4744.WebDataGridItemTemplate.zip