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.
Thank you for the code, Vasya, that really helped me.
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?
Please do not hesitate to contact me if you have any additional questions regarding this matter.