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.
Thanks for the reply. Its worked,
I got "A cell value can only be set for cells that are part of an UnboundField" exception when i try to add value to the bound column on InitializeRow Event of the grid.
How to solve this or Is there any other event available to update the value(append some special character).
I am glad to hear my solution works for you!
Do you need to add these special characters to the actual data of the cells, or do you need to change it only for the user to see?
If the special characters need to be added to the actual data, I would recommend adding it to your datasource. If not, rather than setting the cell's Value property, you can freely edit the cell's Text property, which will display the special characters, but not affect the data.
If you need further assistance with this, please let me know.
Please let me know if you have any other questions or concerns about this issue.