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?
Thank you for the code, Vasya, that really helped me.
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
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:
[code]
protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
If(e.Row.Index == 0)
//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();
I hope you find this information helpful.
Please 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 BlueWhale,
Please do not hesitate to contact me if you have any additional questions regarding this matter.