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

DropDownList Error when in Multi-Line Edit Mode

2 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ciaran Fletcher
Top achievements
Rank 1
Ciaran Fletcher asked on 18 Jul 2012, 07:07 PM
I have a requirement to have Grid where all the rows can be edited. I have the Grid opening with the Rows in Editmode. However, one of the columns is a DropDownList. We are doing the databind to the datasource for the drop down inside the ItemDataBound Event of the Grid. On the first Row, the dropdown works fine However, for anything other than the first row being edited, it shows the Type of the Datasource, and not the values. (See attached image)

Inside the ItemDataBound:
if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
                {
                    GridEditableItem editedItem = e.Item as GridEditableItem;
                    GridEditManager editMan = editedItem.EditManager;
 
                   // Drop down for Status
                    GridDropDownListColumnEditor editor = editMan.GetColumnEditor("PStatusID") as GridDropDownListColumnEditor;
                    editor.DataSource = pStatuses;
                    editor.DataTextField = "Name";
                    editor.DataValueField = "PStatusID";
                                          editor.DataBind();
}

This is the Column definition:
<telerik:GridDropDownColumn DataField="PStatusID" FilterControlAltText="Filter PStatusID column"
                            HeaderText="Status" UniqueName="PStatusID" ItemStyle-Width="80px">
                             
                        </telerik:GridDropDownColumn>

I can't post the whole code due to confidentiality issues, unfortunately.
We are using the Q2 2012 version of the controls.


many thanks.

2 Answers, 1 is accepted

Sort by
0
Ciaran Fletcher
Top achievements
Rank 1
answered on 19 Jul 2012, 06:32 PM
I managed to get it working. I changed the Column to a GridTemplateColumn with a Combobox in it:
<telerik:GridTemplateColumn DataField="StatusID" FilterControlAltText="Filter StatusID column"
                                   HeaderText="Status" UniqueName="StatusID" >                                  
                                    <EditItemTemplate>
                                       <telerik:RadComboBox ID="StatusCombo" runat="server"
                                       </telerik:RadComboBox>
                                 </EditItemTemplate>
                               </telerik:GridTemplateColumn>
In the isInEditMode part of the ItemCommand, I bind the ComboBox:
RadComboBox RadComboBoxStatus = (RadComboBox)editedItem["StatusID"].FindControl("StatusCombo");
                   RadComboBoxStatus.DataSource = pStatuses;
                   RadComboBoxStatus.DataTextField = "Name";
                   RadComboBoxStatus.DataValueField = "StatusID";
                   RadComboBoxStatus.DataBind();

And then in the UpdateCommand, instead of extracting the values and looping around to get each field, I find the Control and get the value directly:
// Get the Status Combo
               ControlCollection ccStatus = item["StatusID"].Controls;
               RadComboBox comboStatus = (RadComboBox)item["StatusID"].FindControl("StatusCombo");
               int pStatusComboVal = Convert.ToInt32(comboStatus.SelectedItem.Value.ToString());

This now shows correct values for each combobox on any edited rows.
0
Tsvetoslav
Telerik team
answered on 23 Jul 2012, 01:27 PM
Hi Ciaran,

Good to know you have resolved the issue.

Regards,
Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Ciaran Fletcher
Top achievements
Rank 1
Answers by
Ciaran Fletcher
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or