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

[Solved] GridDropDownListColumnEdit binding on insert in grid with no records

1 Answer 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 2
James asked on 06 May 2009, 04:47 PM
I'm having some difficulty binding the GridDropDownListColumnEditor for an "InPlace" insert on a grid that is initially loaded with no records. I've gone through the forums, and I've implemented several of the suggested solutions to no avail. The DropDownList displays with no records bound to it. Am I doing something wrong?

To provide some context, I am looking to avoid SqlDataSource controls, as it would break away from our current architecture. I was able to bind the grid by using a SqlDataSource and setting the DataSourceID property of the GridDropDownColumn, but in doing that, I lost the formatting provided by the columneditor control.

Please advise...

Here is my code (ASPX):

                                        <telerik:RadGrid ID="grdClientAddresses" runat="server"  
                                            OnItemDataBound="grdClientAddress_ItemDataBound"  
                                            Visible="true"  
                                            AutoGenerateColumns="false"  
                                            Skin="Office2007"  
                                            Width="800"  
                                            AllowPaging="true"
                                            <MasterTableView  
                                                EditMode="InPlace"  
                                                CommandItemDisplay="Top"   
                                                DataKeyNames="ClientAddressID"
                                                <CommandItemSettings  
                                                    AddNewRecordText="New Address"  
                                                    AddNewRecordImageUrl="/images/office.png"  
                                                    RefreshText="Reload" />                                                  
                                                <NoRecordsTemplate> 
                                                    No addresses exist for this client. Use the fields above to create a new address 
                                                </NoRecordsTemplate>                                                                                           
                                                <Columns>                                                     
                                                    <telerik:GridBoundColumn UniqueName="Address_StreetAddress"  
                                                        HeaderText="Street Address"  
                                                        ColumnEditorID="StreetAddressColumnEditor"  
                                                        HeaderStyle-Width="400"  
                                                        ItemStyle-Width="400"  
                                                        DataField="StreetAddress"
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridBoundColumn UniqueName="Address_City"  
                                                        HeaderText="City"  
                                                        ColumnEditorID="CityColumnEditor"  
                                                        DataField="City"  
                                                        HeaderStyle-Width="260"  
                                                        ItemStyle-Width="260"
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridDropDownColumn UniqueName="Address_StateID"  
                                                        DataField="StateID"  
                                                        ColumnEditorID="StateColumnEditor"  
                                                        HeaderText="State"  
                                                        HeaderStyle-Width="50"  
                                                        ItemStyle-Width="50"
                                                    </telerik:GridDropDownColumn> 
                                                    <telerik:GridBoundColumn UniqueName="Address_ZipCode"  
                                                        HeaderText="Zip"  
                                                        DataField="Zip"  
                                                        ColumnEditorID="ZipCodeColumnEditor"  
                                                        HeaderStyle-Width="90"  
                                                        ItemStyle-Width="90"
                                                    </telerik:GridBoundColumn> 
                                                </Columns>                                                                                                  
                                            </MasterTableView>                                                                                                                                                                                                                              
                                        </telerik:RadGrid>                                                 
                                        <telerik:GridDropDownListColumnEditor ID="StateColumnEditor" runat="server" 
                                            DataTextField="StateAbbr"  
                                            DataValueField="StateID"  
                                            DropDownStyle-Width="50"
                                        </telerik:GridDropDownListColumnEditor>                                                                                
                                        <telerik:GridTextBoxColumnEditor ID="StreetAddressColumnEditor" runat="server" 
                                            TextBoxStyle-Width="350"
                                        </telerik:GridTextBoxColumnEditor> 
                                        <telerik:GridTextBoxColumnEditor ID="CityColumnEditor" runat="server"  
                                            TextBoxStyle-Width="220"
                                        </telerik:GridTextBoxColumnEditor> 
                                        <telerik:GridTextBoxColumnEditor ID="ZipCodeColumnEditor" runat="server"  
                                            TextBoxStyle-Width="60"
                                        </telerik:GridTextBoxColumnEditor>  






And my code behind OnItemDataBound event:

        protected void grdClientAddress_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item.IsInEditMode) 
            { 
                if (e.Item is GridEditableItem) 
                { 
                    //first reference the edited grid item    
                    GridEditableItem EditableItem = e.Item as GridEditableItem; 
                    GridEditManager EditableItemMgr = EditableItem.EditManager; 
 
                    //reference the column editor which holds the dropdown list instance in the edit form   
                    GridDropDownColumnEditor StateDropDownEditor = EditableItemMgr.GetColumnEditor("Address_StateID"as GridDropDownColumnEditor; 
 
                    //bind the column editor 
                    StateDropDownEditor.DataSource = base.DataPortal.GetStates(); 
                    StateDropDownEditor.DataTextField = "StateAbbr"
                    StateDropDownEditor.DataValueField = "StateID"
                    StateDropDownEditor.DataBind(); 
 
                    StateDropDownEditor.SelectedIndex = 0; 
                } 
            }    
        } 
                               
 Thanks!              


1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 11 May 2009, 01:15 PM
Hello James,

I have already answered to the support ticket opened on this matter.
Here is a quote of the answer:

Hello James,

Thank you for contacting us and for your question.

I carefully reviewed your ASP.NET page and noticed that you open a new ASPX page as an edit/insert form. I suppose when the page is opened you populate the controls with the correct data depending on the id passed with the
QueryString. In this case you do not have auto-generated grid editors and that is the reason why the populated data is not shown.

Please examine these online demos which implement some of the required information:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid

Let me know how it goes.

If you do not mind we will continue the communication in the started support thread on this issue in order to avoid duplicate discussions. In this way you will be in touch how the resolution of the problem goes.

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
James
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Share this question
or