This is a migrated thread and some comments may be shown as answers.

GridView control dynamic column binding

3 Answers 475 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chandra Sekhar
Top achievements
Rank 1
Chandra Sekhar asked on 24 Jul 2018, 08:12 PM

Hi,

I have a requirement to implement a screen to show information in a grid with distinct columns/data for each button click(3 buttons).

For e.g., Button1_Click -> Grid must render columns ( Column1, Column2)

               Button2_Click -> Grid must render columns ( Column11, Column12, Column13)

               Button3_Click -> Grid must render columns ( Column21, Column22, Column23, Column24 etc.,)

I do not want to have 3 different grids for each button click by show/hide and have their exclusive bindings just because i feel it is not a right approach. Also I should be able to bind my data fields appropriately to the columns. I really appreciate if someone can share their experience to achieve this in a manageable and scalable way. Hope the scenario is self explanatory. Thanks in advance.

Regards,

Chand.

 

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 27 Jul 2018, 02:10 PM
Hello Chand,

Defining a separate instance of RadGridView for each set of columns would not be needed. You can use a single one and manipulate its Columns collection by adding/removing the needed columns. The approach of defining columns is discussed in details in this help article. So, for this case you can manually define the required columns and add them to the aforementioned collection.

Hope this helps.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chandra Sekhar
Top achievements
Rank 1
answered on 13 Aug 2018, 06:15 PM

Hi Stefan,

Thanks for the solution. I have used the Automatic column creation by using AutoGenerateColumns="True" and getting what I want except an issue. I am changing my itemsource by user's action in the UI and each source has different number of columns in its datasource. When i change the itemsource from a higher number of columns datasource(Say 5) to lower number of columns datasource(Say 3) the data actually updates the grid with appropriate columns data and its column headers however the difference of columns ( in this case 2 ) still showing as last columns in the grid with empty data. I have tried various ways of remove/clearing these unwanted columns but in vain. Is this not supported currently? Suggestions on ways to handle this is much appreciated.

Thanks.

0
Stefan
Telerik team
answered on 15 Aug 2018, 11:46 AM
Hi Chand,

My best guess is that you refer to the rows taking the available space of the grid when there are less columns. Note, that the empty space is not an additional column. If this is the case you can either set the Width of the last column to be Star(*), or set the ColumnWidth property of RadGridView to *. The first approach would be make the last column fill all the available space, whereas the second one would make all columns fill the available space proportionally.

Can you please give the suggestion a try?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Chandra Sekhar
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Chandra Sekhar
Top achievements
Rank 1
Share this question
or