My webdatagrid getting data from a datasource. After assigning into the datasource, I like to format column headers, hide some columns and format cells. Usually in ultradatagrid we do this through Initialize layout event. How to achieve the same in webdatagrid?
Hello BlueWhale,
Thank you for posting in the community.
I know it`s been a while since you posted but if you are still in a need of assistance I would be glad to help.
Columns collection in WebDataGrid contains only the columns objects that were added by hand in either aspx or in the code behind file. The autogenerated columns are for display purpose only, they cannot be accessed or modified.
WebDataGrid works with items instead of columns. What I can suggest for achieveing you requirement is handling InitializeRow event and set the colum headers, whether the column to be hidden or not etc. as such:
[code]
protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
{
//reffer to a particular column in the grid
e.Row.Items[0].Column.Header.Text ="Enter your header text here";
e.Row.Items[0].Column.Hidden =true;
//reffer to a particular cell in the grid
var cellText = e.Row.Items[0].Value.ToString();
}
Please keep in mind that you have to have at least one row initialized in the grid in order to fire the Initialize Row event.
I hope you find this information helpful.
Feel free to contact me if you have any additional questions regarding this matter.
This seems rather inefficient if I am understanding correctly. Wouldn't this mean this code is run for every row in the dataset when in fact it really should just be done once?
Hello spietros,
Thank you for sharing your concerns in our community.
You suggestion is correct - this event will be fired every time a row in the grid is initialized. However, what I can suggest in order to run the code just once is to check the row index and perform the code only for the first row with index 0. For example:
If(e.Row.Index == 0)
Please feel free to contact me if you have any additional questions regarding this matter.
Hi,
I was using Ultragrid control which has _InitializeLayout event. Now I am migrating to WebDataGrid which does not have this event so I have used below code to fix my columns.
ColumnFixing fixingBehavior = this.WDGLinkedViewDetails.Behaviors.GetBehavior<ColumnFixing>();
if (fixingBehavior == null)
fixingBehavior = WDGLinkedViewDetails.Behaviors.CreateBehavior<ColumnFixing>();
if (WDGLinkedViewDetails.Columns[columnKey] != null)
fixingBehavior.FixedColumns.Add(columnKey);
if (isLastFixedColumn)
AddFixedColumnStyle(columnKey);
fixingBehavior.Enabled = true;
fixingBehavior.FixedColumns.Add(columnKey); piece of code is triggering event WebDataGrid_InitializeRow event.
We have put lot of code to manipulate each row in WebDataGrid_InitializeRow. We have to fix the column on basic of various conditions so if I have to fix three columns (for example), the WebDataGrid_InitializeRow would called thrice which causing performance issues.
Please suggest me how to avoid this event call.
Thanks, Manoj