Autogenerated columns seem to be cached between different datasources

6 posts, 1 answers
  1. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 04 Feb 2008 Link to this post

    Hi,
    I had a rad grid which gets bound a totally different datasource based on certain events. I have enabled autogenerated columns and this works all fine. I have some logic on the ColumnCreated event to set the visible flag on the column based on some criteria. This is all working fine.

    However, i have noticed that if there are columns with the same names, in two different datasources, the autogenerated column property gets cached!

    E.g I have DataSource1 and DataSource2. Both contain a column called UserId. When displaying DataSource1 i want to hide that column. I do that by setting the visible property to false. When I switch to datasource2, i do not want to hide this column, but it still hides it (even though the visible property is set to true)! If i switch to a different datasource (i.e datasource3) which does not contain a column of the same name, and then switch back to datasource2, it will display that column....
    What I need is some way of letting the RadGrid know that it needs to regenerated all the autogenerated columns, even though they may have the same name.
    Or if possible, a way to add a custom prefix to the UniqueName of the autogenerated columns

    Below is the code I use to set the visible property:
     void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
        { 
            if (myAdminTree != null && myAdminTree.SelectedNode != null
            { 
                string uniqName = e.Column.UniqueName; 
                
                if (myAdminTree.CurrentDataKeyNames.Contains(uniqName)) 
                { 
                    e.Column.Visible = false
                } 
            } 
        } 


    Thanks,
  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 06 Feb 2008 Link to this post

    Hello,

    If the columns have the same name, they will remain invisible, as per the code sample included.
    You can further differentiate between the columns, by checking the e.OwnerTableView property, which would give you access to the mastertable, in which the columns are nested, and thus have a chance to toggle their visibility on/off, based on the mastertable differences.
    Additionally, the following article contains additional information pertaining to altering the control structure dynamically.
    I hope this information helps.

    Sincerely yours,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 06 Feb 2008 Link to this post

    Sorry, I think you have not understood what I meant ... let me try to elaborate.

    I have 3 totally different datasources: e.g

    DataSource1 has columns: UserID UserName Password

    DataSource2 has columns: RecId,RecName,UserId

    DataSource3 has columns: DiffId, DiffName,DiffField

    The grid is initially bound to datasource1. The grid is a simple one table grid, no hierarchy or nesting. Based on some logic, the autogenerated userId column is set to be invisible for this case.

    The user intereacts with the page, and now causes the grid to bind to a different datasource, DataSource2.

    Based on the criteria, all the columns should remain visible. When i step through the debugger in Visual Studio all the columns have their visible property set to true. But when the grid is rendered on the page, the UserId column(which is hidden in datasource1) does not display.

    If the user now interacts with the page again and causes the grid to bind to datasource3 (which does not have a column called UserID), and then interacts once more to cause the grid to bind back to datasource2, the UserID field becomes visible

    The settings on the RadGrid is to AutoGenerateColumns.

    From what I can see, it seems that the RadGrid is making an assumption that autogenerated columns of the same name do not need to be regenerated, even though the datasource has changed. If the datasource does not contain a definition for a particular column it is removed, hence the reason it works correctly if i switch between datasources which do not set different values of the visible property for columns of the same name, or if the column names between the datasources do not overlap

    Thanks again,
    Fayez
  5. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 11 Feb 2008 Link to this post

    Hi,

    You can try explicitly toggling on the visibility of the column.
    This is demonstrated in the sample project attched to this message.
    Let me know how it goes.

    Greetings,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 11 Feb 2008 Link to this post

    I think I found my problem. I was trying to toggle the visibility in the ColumnCreated event, but i think this was too early and it was being overwritten. I now just hook into the RadGrid DataBound event, and then iterate through all the autogenerated columns and set the properties appropriately. It works as its supposed to now.
    Is there somewhere where we can see the RadGrid lifecycle, in terms of its events and when it is being rebound etc

    Thanks
  7. Answer
    Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 12 Feb 2008 Link to this post

    Hello EmpowerIT,

    To familiarize with the event lifecycle and sequence of RadGrid Prometheus review the Controls -> RadGrid -> The control lifecycle chapter from the online documentation:

    http://www.telerik.com/help/radcontrols/prometheus/

    Best,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017