Hi,
I have bound datasource to the DataWebGrid, In which i have more than 15 columns and i want to display only 10 columns, How to do that in code behind.I need to make the visibility of column at runtime
And also i need to find the Visible Rows,
foreach(GridRecord item in WebGrid.Rows)
{
if(item.Hidden == false)
}
Item.Hidden property is not there in GridRecord.
Thanks & Regards,
Developer
Hello Tanya,
Thank you for posting in our forums!
To hide your columns, you will need to access the GridField objects. You can access the columns through the WebGrid.Columns collection. Each GridField (column) has a Hidden property that can be used to hide the column. Please see our documentation for this property below:
http://help.infragistics.com/doc/ASPNET/2014.1/CLR4.0/?page=Infragistics4.Web.v14.1~Infragistics.Web.UI.GridControls.ControlDataField~Hidden.html
Please note, if you have AutoGenerateColumns set to true, you will not be able to use the WebGrid.Columns collection. In this case, you should access the columns through a databound row. i.e. WebGrid.Rows[0].Items[0].Column.Hidden.
As for finding visible rows; rows are not able to be hidden with a property. All rows that are bound to the grid should always be visible. Are you referring to finding rows that have been filtered out or that exist on another page?
If you need any further assistance with this, please let me know.
Thanks for your reply Michael.
I need to hide 5 columns, but in my datasource i have 15 columns, When binding the data to the grid itself i need to hide the columns based on some conditions.
how can i achieve that in code behind. The column names are not known until the datasource bind to the grid.
Thanks,
Tanya
And also i need to find the Bound Column count, but WebGrid.Columns.Count didnt work, how to retrieve the Bounded column count in the Code behind.
Please give some samples for WebDataGrid with bound columns and manipulation of columns in codebehind file.
Hi Tanya,
It sounds like you are using AutoGenerateColumns to create your columns. As I mentioned in my previous update, in order to get the number of columns when using AutoGenerateColumns, you will need to access the columns through the Rows collection after the data is bound. You can find the count of columns with the following code:
WebGrid.Rows[0].Items.Count
If you need to customize and make changes to the columns, it is recommended to set AutoGenerateColumns to false and to add the columns to the grid yourself. If you know the columns during design time, you can add them directly to the column collection through markup or code behind. If you do not know the columns, you can analyze your datasource to determine how to add your columns to the grid. This is essentially what AutoGenerateColumns does anyway and doing this yourself would give you more control over the columns. You can find more information on dynamically adding rows to the grid in our documentation here:
http://help.infragistics.com/doc/ASPNET/2014.1/CLR4.0/?page=WebDataGrid_Add_or_Remove_a_Column.html
I have attached a sample that demonstrates how you can analyze a DataTable and add the necessary columns and also provide customizations to certain columns.
If you have any further questions or concerns with this, please let me know.