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

Changing EditMode to 'InPlace' breaks DropDownList

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wilco Rogers
Top achievements
Rank 1
Wilco Rogers asked on 06 Jun 2013, 06:04 PM
Hello,

I currently have a rad grid that on row insert and edit command displays a regular ASP DropDownList box populated from code behind in the OnItemDataBound event handler. Everything is working fine, the values are populated and the data is stored on insert/update, however changing the EditMode to InPlace on the master table view creates an empty box with no data populated. What is changing here?

Here is the first part of my ASP for the grid

<telerik:RadGrid ID="OrderItemGrid" runat="server" AutoGenerateColumns="False"
    CellSpacing="0" GridLines="None">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="OrderItemID" EditMode="InPlace">
        <CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Quick-Add New Order Item" />
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
            Visible="True">
        </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
            Visible="True">
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="OrderItemID"
                FilterControlAltText="Filter OrderItemID column" HeaderText="Item ID"
                ReadOnly="True" UniqueName="OrderItemID">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn DataField="CatID" FilterControlAltText="Filter CatID column" HeaderText="Category" UniqueName="CatID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DDCategory" runat="server"></asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DDCategory" runat="server"></asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="CatIDLabel" runat="server" Text='<%# Eval("CatID") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>


And here is the relevant code-behind


Protected Sub OrderItemGrid_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles OrderItemGrid.ItemDataBound
    If TypeOf (e.Item) Is GridEditFormInsertItem And e.Item.IsInEditMode Then
        Dim editItem As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
        Dim dropList As DropDownList = CType(editItem("CatID").FindControl("DDCategory"), DropDownList)
        Using dbContext As New MatrixORMModelVB()
            dropList.DataSource = dbContext.Categories.ToList()
            dropList.DataTextField = "CategoryName"
            dropList.DataValueField = "CategoriesID"
            dropList.DataBind()
        End Using
    ElseIf TypeOf (e.Item) Is GridDataItem And Not e.Item.IsInEditMode Then
        Dim editItem As GridDataItem = CType(e.Item, GridDataItem)
        Dim label As Label = CType(editItem("CatID").FindControl("CatIDLabel"), Label)
        Using dbContext As New MatrixORMModelVB()
            Dim temp As String = label.Text
            Dim tempCat As MatrixORM.Category = dbContext.Categories.Where(Function(c) c.CategoriesID = temp).First()
            label.Text = tempCat.CategoryName
        End Using
    End If
End Sub

If I remove EditMode="InPlace" from the MasterTableView things work perfectly. Why the difference?

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jun 2013, 05:39 AM
Hi ,

I have tried an example,and it works fine for me, please use,
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode    instead of 
If
TypeOf (e.Item) Is GridEditFormInsertItem And e.Item.IsInEditMode

This is part of code which i tried.

C#:
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           // access/modify the edit item template settings here
           DropDownList list = item.FindControl("DDCategory") as DropDownList;
           list.DataSource = SqlDataSource1;
           list.DataTextField = "ColumnName";
           list.DataValueField = "ColumnName";
           list.DataBind();
 
       }

Thanks,
Princy
Tags
Grid
Asked by
Wilco Rogers
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or