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 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:
protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
//reffer to a particular column in the grid
e.Row.Items.Column.Header.Text ="Enter your header text here";
//reffer to a particular cell in the grid
var cellText = e.Row.Items.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.