As a follow up to the earlier question beneath, I'm trying to write some code to assign contacts to facilities.
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-reference-parent-data-items-in-edititemtemplate.aspx
I'm following samples such as the one beneath but I'm unable to find the correct event that I need to use. I'm currently trying to use 'RadGrid1_InsertCommand' but I imagine that's not working because it's the event that would be used for inserting the parent 'Facilities'.
http://www.telerik.com/community/code-library/aspnet-ajax/grid/automatic-operations-in-hierarchical-grid-with-sqldatasource-control.aspx
Can someone tell me what event I need to be looking at?
Thanks,
Tim
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-reference-parent-data-items-in-edititemtemplate.aspx
I'm following samples such as the one beneath but I'm unable to find the correct event that I need to use. I'm currently trying to use 'RadGrid1_InsertCommand' but I imagine that's not working because it's the event that would be used for inserting the parent 'Facilities'.
http://www.telerik.com/community/code-library/aspnet-ajax/grid/automatic-operations-in-hierarchical-grid-with-sqldatasource-control.aspx
Can someone tell me what event I need to be looking at?
Thanks,
Tim
Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) 'This event is not firing when I click on the 'Insert' link. What event do I need to use instead? Dim insertedItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem) Dim parentItem As GridDataItem = e.Item.OwnerTableView.ParentItem Dim datakey As String = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("FacilityID").ToString() Dim contactId As Integer = (TryCast(insertedItem("colContactId").Controls(0), DropDownList)).SelectedValue Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Try conn.Open() Dim insertQuery As String = "INSERT into FacilityContacts(FacilityId, ContactID) values('" & datakey & "','" & contactId & "')" Dim cmd As New SqlCommand(insertQuery, conn) cmd.ExecuteNonQuery() conn.Close() Catch ex As Exception RadGrid1.Controls.Add(New LiteralControl("Unable to insert contact. Reason: " + ex.Message)) e.Canceled = True Finally End TryEnd Sub<telerik:RadGrid ID="RadGrid1" ShowStatusBar="True" DataSourceID="dsFacilityList" runat="server" PageSize="7" AllowSorting="True" AllowPaging="True" GridLines="None" CellSpacing="0" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" > <PagerStyle Mode="NumericPages"></PagerStyle> <MasterTableView DataSourceID="dsFacilityList" AllowMultiColumnSorting="True" PageSize="20" CommandItemDisplay="Top" DataKeyNames="FacilityID" EditMode="EditForms" > <EditItemTemplate> </EditItemTemplate> <DetailTables> <telerik:GridTableView runat="server" DataKeyNames="FacilityID" DataSourceID="dsFacilityContactList" CommandItemDisplay="Top" AutoGenerateColumns="False" AllowAutomaticDeletes="True" AllowAutomaticInserts="False"> <EditItemTemplate> </EditItemTemplate> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="FacilityID" MasterKeyField="FacilityID" /> </ParentTableRelation> <CommandItemSettings ExportToPdfText="Export to PDF" /> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> <HeaderStyle Width="20px" /> </ExpandCollapseColumn> <Columns> <telerik:GridTemplateColumn DataField="ContactID" FilterControlAltText="Filter column column" UniqueName="colContactId" EditFormHeaderTextFormat=""> <EditItemTemplate> Select Contact: <asp:DropDownList ID="cboContactID" runat="server"> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="ContactIDLabel" runat="server" Text='<%# Eval("ContactLongDesc") %>'></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </telerik:GridTableView> </DetailTables> <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True"> </ExpandCollapseColumn> <SortExpressions> </SortExpressions> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu></telerik:RadGrid>