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

RadGrid Drop Down List will not Bind

0 Answers 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 04 Jan 2018, 12:38 PM

I have 2 ASPX pages that use the same simple Telerik RadGrid.  Here is my ASP code for these RadGrids:

<div id="GridViewArea" style="border-style: solid; border-width:0px; margin-top: 10px; width: 600px;">
                <telerik:RadGrid ID="RadGrid1" runat="server"
                    OnItemCreated="RadGrid1_ItemCreated"
                    OnInsertCommand="RadGrid1_InsertCommand"
                    OnItemInserted="RadGrid1_ItemInserted"
                    OnItemDataBound="RadGrid1_ItemDataBound"
                    AllowAutomaticInserts="false"
                    AllowAutomaticUpdates="false"
                    OnUpdateCommand="RadGrid1_UpdateCommand"
                    AutoGenerateColumns="false">
                    <MasterTableView
                        AutoGenerateColumns="false"
                        CommandItemDisplay="Top"
                        NoMasterRecordsText="No Rides have been recorded for this rider."
                        DataKeyNames="RideID"
                        Font-Size="Medium">
                        <Columns>
                            <telerik:GridBoundColumn HeaderText="RiderID" DataField="RiderID" ReadOnly="true" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn UniqueName="DateTemplateColumn" HeaderText="Ride Date">
                                <ItemTemplate>
                                    <asp:Label ID="DateEditItemTemplate" runat="server"
                                        Text='<%# DataBinder.Eval(Container.DataItem, "RideDate","{0:MM/dd/yyyy}") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadDatePicker ID="dpRideDate" UniqueName="dpRideDate" DateInput-DateFormat="MM/dd/yyyy" MinDate="1999/1/1" runat="server" DbSelectedDate='<%# Bind("RideDate") %>'>
                                    </telerik:RadDatePicker>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DeputyTemplateColumn" HeaderText=" Deputy">
                                <ItemTemplate>
                                    <asp:Label ID="DeputyEditItemTemplate" runat="server"
                                        Text='<%# DataBinder.Eval(Container.DataItem, "Deputy") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="ddlDeputy" runat="server" UniqueName="ddlDeputy" DataTextField="Name" DataValueField="EID" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="SectorColumn" HeaderText="Sector">
                                <ItemTemplate>
                                    <asp:Label ID="SectorEditItemTemplate" runat="server"
                                        Text='<%# DataBinder.Eval(Container.DataItem, "SectorDescription") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="ddlSector" runat="server" UniqueName="ddlSector" DataTextField="SectorDescription" DataValueField="SectorValue" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
 
                    </MasterTableView>
                </telerik:RadGrid>
            </div>

 

Note the RadGrid is within an asp:UpdatePanel

I have 2 DropDown Lists used to add a new record to the grid and I bind these DropDown Lists in the RadGrid1_ItemDataBound Method here is that code:

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                using (var db = new RideTracker2018Entities())
                {
                    var sectors = (from c in db.LU_Sectors
                                   select new { c.SectorDescription, c.SectorValue }).ToList();
                    GridEditableItem item = e.Item as GridEditableItem;
                    // access/modify the edit item template settings here
                    DropDownList list = item.FindControl("ddlSector") as DropDownList;
                    list.DataTextField = "SectorDescription";
                    list.DataValueField = "SectorValue";
                    list.DataSource = sectors;
                    list.DataBind();
 
                    var deputies = (from c in db.VW_DeputyInfo
                                    select new { c.Name, c.EID }).ToList();
                    GridEditableItem item2 = e.Item as GridEditableItem;
                    DropDownList list2 = item2.FindControl("ddlDeputy") as DropDownList;
                    list2.DataTextField = "Name";
                    list2.DataValueField = "EID";
                    list2.DataSource = deputies;
                    list2.DataBind();
                }
 
            }
        }

 

The grid renders and works as planned on one page but on the second page the DDDLs will not bind.  On the second page the code to bind the lists does not run because it fails to pass the if (e.Item is GridEditableItem && e.Item.IsInEditMode).

Can anyone explain why these identical RadGrids are not working the same?

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Perry
Top achievements
Rank 1
Share this question
or