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

[Solved] InPlace Editing Selected Value

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe Tusing
Top achievements
Rank 1
Joe Tusing asked on 30 Jul 2009, 04:54 PM
Hello,

I have InPlace editing enabled and I'm using an Edit ItemTemplate in order to create validation on some of the fields using drop-down lists.

My question is how can I set the selected value on the drop-down list to be the value of the item before it was in edit mode?
The drop-down list populated correctly but by default displays the first item in the list.
It seems as though there should be SelectedValue property for the DropDownList but there isn't.

Any help is greatly appreciated.

- Joe


UOM is the name of my DataField
<telerik:GridTemplateColumn UniqueName="UnitOfMeasureNative" Display="true" ItemStyle-HorizontalAlign="Center" 
                                    HeaderText="UOM (Native)"
                                     
                                    <ItemTemplate>                           
                                        <asp:Label runat="server" ID="lblUnitOfMeasureNative" Text='<%# Eval("UOM") %>'
                                        </asp:Label> 
                                    </ItemTemplate> 
                                    <EditItemTemplate> 
                                        <asp:DropDownList runat="server" ID="ddlUOMNative" 
                                            DataTextField="Abbreviation" 
                                            DataValueField="ID" 
                                            DataSource='<%# Pace.Ecolink.Data.Factory.UOMFactory.GetUOMList()  %>'
                                        </asp:DropDownList>        
                                    </EditItemTemplate> 
                                </telerik:GridTemplateColumn> 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Jul 2009, 05:21 AM
Hello Joe,

You can try out the following code to achieve the required scenario:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = (GridEditableItem)e.Item; 
            DropDownList ddl = (DropDownList)item.FindControl("ddlUOMNative");             
            ddl.SelectedIndex = item.ItemIndex; 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Joe Tusing
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or