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

RadGrid Missing Column Values

14 Answers 647 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sharon Kalupske
Top achievements
Rank 1
Sharon Kalupske asked on 23 Sep 2008, 02:00 PM

Can you help me shed some light on the following issue?

Problem:

I have a grid with in-place edit and three records.  One column is a griddropdowncolumn.  When the grid loads, the values are not displayed for this column. 

When I enter the edit mode, values are rendered in this column.

Case A:

If I press the edit button on the first record the dropdown is populated, the correct value is selected in the dropdown and the remaining two records now have a value displayed in this column.  If I cancel the edit and return to the gridview the column no longer displays values in this column for any of the records. 

Case B:

If I press the edit button of the middle record the dropdown is populated, the correct value is selected in the dropdown, the first record does not display a value for this column but the third record does display a value for this column.  If I cancel the edit and return to the gridview the column no longer displays values in this column for any of the records

 

Detail about the grid and the GridDropDownColumn:

The grid and its dropdown column are bound to datatables contained within the same dataset. 

The griddropdowncolumn is defined as follows:

<telerik:GridDropDownColumn

 DataField="Country_code"        (field name in the grid source)

GroupByExpression="Country_Code"

HeaderText="Country Code" 

SortExpression="Country_Code"

UniqueName="Country_Code"

ListTextField="Name"                   (field name in dropdown source)

ListValueField="Country_code"  />         (field name in dropdown source)

 

The grid is bound to a datatable in the dataset during the NeedDataSource event.

                grdAccounts.DataSource = BusinessAccounts.Tables["Business_Accounts"];

When in EditMode the dropdowncolumn is bound to one of the datatables in the dataset during the ItemDataBound event.

GridEditableItem editedItem = e.Item as GridEditableItem;

               GridEditManager editMan = editedItem.EditManager;

               GridDropDownColumnEditor editor =

                            editMan.GetColumnEditor("country_code") as GridDropDownColumnEditor;

               editor.DataSource = BusinessAccounts.Tables["Countries"];

               editor.DataBind();

               editor.SelectedValue = editedItem.GetDataKeyValue("Country_Code").ToString();

The ListValueField and the DataField are the same data type and length.

Thanks for your help.

 

14 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 23 Sep 2008, 06:00 PM
I am having the same issue with the GridDropDownColumn.  None of them are populating properly when I go into Edit mode.  My grid's datasource is being filled from a LINQ to SQL query in codebehind.  Here's the code in my ASPX:

<telerik:GridDropDownColumn DataField="PriorityID" DataSourceID="ldsPriorities" HeaderText="Assignment Priority" ListTextField="ValueName" ListValueField="ValueID" UniqueName="PriorityID"></telerik:GridDropDownColumn> 

<asp:LinqDataSource ID="ldsPriorities" runat="server" ContextTypeName="MyDataContext" Select="new (ValueID, ValueName)" TableName="AssignmentPriorities" OrderBy="ValueName"></asp:LinqDataSource>

0
Princy
Top achievements
Rank 2
answered on 24 Sep 2008, 07:00 AM
Hello Dave,

GridDropDownColumn will be bound to a data source where each item from RadGrid would have its representation as a value in the dropdown column's source. If an item in RadGrid cannot find a matching value in the lookup source, then it defaults to an empty string. Hence, for the proper functioning of GridDropDownColumn, verify that all column values referenced by the DataField attribute matches the column values referenced by the ListValueField attribute.

For more information on how to populate a dropdowncolumn in edit mode go through the following help link
Customize/Configure GridDropDownColumn

Princy.
0
Jeff
Top achievements
Rank 1
answered on 24 Sep 2008, 01:38 PM

Back to the original post, I am seeing the same thing with respect to the non-edit mode showing an empty label.

What can be said about Case A vs Case B?  It would appear that the RadGrid CAN and IS finding a matching value in the lookup source, but only does so when the grid row above is in edit mode.

I am at a lost, any other ideas?
0
Rosen
Telerik team
answered on 26 Sep 2008, 08:52 AM
Hi Tim,

The behavior you are experiencing is due to the fact that you actually replacing the DataSource for the entire DropDownColumn not just for the current cell. Therefore all cells that are below the one which is in editmode will receive the new datasource. In order to workaround this you can try to temporary store the current datasource, bind the DropDown and then re-assign the datasource, similar to this:

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
              //... other code; get the column editor ...
 
                object tempDataSource = editor.DataSource;  
                editor.DataSource = table;  
                editor.DataBind();  
                editor.DataSource = tempDataSource;  
            }  
        } 

Please give it a try and let us know how it went.

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 26 Sep 2008, 04:09 PM
Rosen, thanks for the information.  The fact that the edit of the 2nd row, changes (and fixes) the datasource for the columns below makes sense with the behavior being seen. 

The work around described would likely work, provided the existing datasource was correct to start with.  When this patch was applied we actually lost ground.  The following results were found for the three grid rows. 
  1. [blank label - bad]
  2. edit mode [drop down list - good]
  3. [blank label - bad]

This patch was rolled back, so I am back at having the rows beneath and edit row working.

  1. [blank label - bad]
  2. edit mode [drop down - good]
  3. [populated label - good]


Humor me as I attempt to re-spin the question.  When the datagrid does not have any of the 3 rows in edit mode ... all 3 rows show a blank label.  
  1. [blank label - bad]
  2. [blank label - bad]
  3. [blank label - bad]

Of course this nearly rectifies itself when I click on row 2.  The result being
  1. [blank label - bad]
  2. edit mode [drop down - good]
  3. [populated label - good]

So, how/where can I set the column datasource besides the ItemDataBound event?

Or, how do I set the datasource for the column when not in edit mode?

Any more ideas?

Thanks!
 

0
Jeff
Top achievements
Rank 1
answered on 26 Sep 2008, 04:09 PM
Rosen, thanks for the information.  The fact that the edit of the 2nd row, changes (and fixes) the datasource for the columns below makes sense with the behavior being seen. 

The work around described would likely work, provided the existing datasource was correct to start with.  When this patch was applied we actually lost ground.  The following results were found for the three grid rows. 
  1. [blank label - bad]
  2. edit mode [drop down list - good]
  3. [blank label - bad]

This patch was rolled back, so I am back at having the rows beneath and edit row working.

  1. [blank label - bad]
  2. edit mode [drop down - good]
  3. [populated label - good]


Humor me as I attempt to re-spin the question.  When the datagrid does not have any of the 3 rows in edit mode ... all 3 rows show a blank label.  
  1. [blank label - bad]
  2. [blank label - bad]
  3. [blank label - bad]

Of course this nearly rectifies itself when I click on row 2.  The result being
  1. [blank label - bad]
  2. edit mode [drop down - good]
  3. [populated label - good]

So, how/where can I set the column datasource besides the ItemDataBound event?

Or, how do I set the datasource for the column when not in edit mode?

Any more ideas?

Thanks!
 

0
Jeff
Top achievements
Rank 1
answered on 26 Sep 2008, 04:57 PM
Ok, I have some more code that is getting me closer.  This code fixes everything, but the first row which is still a blank label (bad).

What I am doing, is expanding the code being used to set the datasource for the drop down.  Instead of only setting the datasource, when the row is in edit mode ... i'm setting it every time.  - not in love with it, but it helps to expose my problem.

The result is

  1. [blank - bad]
  2. [label - good]
  3. [label - good]

So, how can I do this better and how can I get that first row to use the datasource?

        protected void grdAccounts_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem )  
            {  
                foreach (GridColumn col in grdAccounts.MasterTableView.Columns)  
                {  
                    if (col.ColumnType == "GridDropDownColumn")  
                    {  
                        GridEditableItem eeditedItem = e.Item as GridEditableItem;  
                        GridEditManager editMan = editedItem.EditManager;  
 
                        GridDropDownColumnEditor editor = editMan.GetColumnEditor("country_code") as GridDropDownColumnEditor;  
                        editor.DataSource = BusinessAccounts.Tables["Countries"];  
 
                        //Not sure if this is needed, but when executed on a IsInEditMode = false we generate a null error  
                        //if ((e.Item as GridEditableItem).IsInEditMode)  
                        //{  
                        //    editor.DataBind();  
                        //    editor.SelectedValue = editedItem.GetDataKeyValue("Country_Code").ToString();  
                        //}  
 
                    }  
                }  
            }  
        } 
0
Rosen
Telerik team
answered on 29 Sep 2008, 01:28 PM
Hi Tim,

The first item's cell is blank in this case because when ColumnEditor is bound, the first item is already bound. Therefore all except the first item has a value. In your case I suggest you consider using a template column with RadComboBox inside its EditItemTemplate and a Label inside the ItemTemplate, instead of using built-in GridDropDownColumn.

Best regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 29 Sep 2008, 02:24 PM

..., but I'm so close to getting the Telerik built-in GridDropDownColumn working.  I really do not want to add additional complexity when this GridDropDownColumn is all I need.

"The first item's cell is blank in this case because when ColumnEditor is bound, the first item is already bound."

It would appear that there is an bug in the GridDropDownColumn.  When it binds that first item and the later items it acts like it is doing so in error.  This incorrect behavior is re-affirmed when I manually correct this binding. 

Is there a way I can rebind this first row or override the default (errored) binding behavior? 

Is this something I should open a ticket up for?

Thanks!
Tim

0
Rosen
Telerik team
answered on 01 Oct 2008, 07:10 AM
Hello Tim,

The first item is already bound, as the code you are using is inside the event's (ItemDataBound) handler which is fired after the item is databound. GridDropDownColumn executes different logic, creates different controls etc. depending on if it is databound or not. Supplying the DataSource inside ItemDataBound and calling the DataBind method will eventually rebind the GridEditItem's ComboBox, but will not populate the cell's text as they are already created. Therefore you should populate the first item's cell manually. Please have in mind that Column as ColumnEditor's setting are shared among all cells in the current column. Thus all cells will share same DataSource once set.

All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 01 Oct 2008, 04:46 PM
The demo below, I do see that the GridDropDownColumn is working - and without all the work arounds.

The only difference is that the SQL is stored in the markup.  In fact the code-behind is empty.

http://demos.telerik.com/aspnet/Grid/Examples/GeneralFeatures/ColumnTypes/DefaultCS.aspx

Is there a demo that has the SQL defined in the code behind, perhaps using datatables?  Putting SQL in our mark-up is not an option for me.

Other than that, I'm close to giving up on using this built-in control.

Thanks again for the continued support.
Tim

0
Rosen
Telerik team
answered on 03 Oct 2008, 12:33 PM
Hello Tim,

In the example in question the DropDownColumn's DataSource is defined statically, thus it is available before grid items are databound. I have attached example which demonstrates how to bind the DropDownColumn inside RadGrid's ItemCreatedEvent. Please give it a spin and let us know if this helps.

Kind regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Accepted
Jeff
Top achievements
Rank 1
answered on 03 Oct 2008, 09:29 PM
wow!  this demo is looking pretty good.  Thank you.

I will try to implement this approach first thing monday and let everyone know if that was the magic bullet. 

thanks again for creating the demo!

Tim
0
Sharon Kalupske
Top achievements
Rank 1
answered on 06 Oct 2008, 01:24 PM
We implemented the approach suggested in the sample and it seems to have corrected the problem.  So I want to thank Telerik and Tim for your persistance in resolving this issue. 

Thanks again.
Tags
Grid
Asked by
Sharon Kalupske
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Rosen
Telerik team
Sharon Kalupske
Top achievements
Rank 1
Share this question
or