Hey there,
I am struggling to both display my edit form, as well as how to reference and save the data after the user hits submit. I have been searching for a week and have yet to find a solution. I realize that it is likely something in the code-behind, but I am truly at a loss as to where or how I should be referencing the gridcommandeditcolumn. I am pretty new to both ASP and C#, so please refrain from sending me to one of the demo's which I have looked at over and over, and still cannot find the solution.
ASP
And the CodeBehind C#
I am struggling to both display my edit form, as well as how to reference and save the data after the user hits submit. I have been searching for a week and have yet to find a solution. I realize that it is likely something in the code-behind, but I am truly at a loss as to where or how I should be referencing the gridcommandeditcolumn. I am pretty new to both ASP and C#, so please refrain from sending me to one of the demo's which I have looked at over and over, and still cannot find the solution.
ASP
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" MasterPageFile="~/EUEMain.master" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><asp:Content ID="Content1" ContentPlaceHolderID="cphLeftNav" runat="Server"> <asp:HyperLink ID="AddNew" runat="server" Text="Add Subdivision" /> <br /> <asp:HyperLink runat="server" ID="CQ_Tickets" Text="CQ Tickets"></asp:HyperLink></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="Server"> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" /> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"> </telerik:RadAjaxLoadingPanel> <div> <telerik:RadGrid ID="RadGrid1" OnPreRender="RadGrid1_PreRender" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="200" GridLines="None" ShowGroupPanel="true" OnItemCreated="RadGrid1_ItemCreated" OnItemUpdated="RadGrid1_ItemUpdated" OnItemCommand="RadGrid1_ItemCommand" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True"> <PagerStyle Mode="NumericPages"></PagerStyle> <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="SubdivisionId" AllowMultiColumnSorting="True" GroupLoadMode="Server"> <NestedViewTemplate> <asp:Panel runat="server" ID="InnerContainer" Visible="False"></asp:Panel> <telerik:RadTabStrip runat="server" ID="TabStip1" MultiPageID="Multipage1" SelectedIndex="0"> <Tabs> <telerik:RadTab runat="server" Text="Details" PageViewID="PageView1"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Collection" PageViewID="PageView3"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Editing" PageViewID="PageView4"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Publishing" PageViewID="PageView5"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Testing" PageViewID="PageView6"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Production" PageViewID="PageView7"> </telerik:RadTab> </Tabs> </telerik:RadTabStrip> <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"> <telerik:RadPageView runat="server" ID="PageView1"> <asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("SubdivisionId") %>' Visible="False" runat="server"></asp:Label> <telerik:RadGrid runat="server" ID="PrepDetailGrid" DataSourceID="SqlDataSource2" ShowFooter="true" AllowSorting="true" EnableLinqExpressions="false"> <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true" DataSourceID="SqlDataSource2" DataKeyNames="TrackDatabaseId" PageSize="25" HierarchyLoadMode="ServerOnDemand" EditMode="EditForms"> <Columns> <telerik:GridBoundColumn SortExpression="Version" HeaderText="Version" HeaderButtonType="TextButton" DataField="Version" UniqueName="Version"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Status" HeaderText="Status" HeaderButtonType="TextButton" DataField="SubStatus" UniqueName="Status"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Proposed RSD Date" HeaderText="Proposed RSD Date" HeaderButtonType="TextButton" DataField="ProposedRSDDate" UniqueName="ProposedRSDDate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Collection" HeaderText="Collection" HeaderButtonType="TextButton" DataField="Collection" UniqueName="Collection"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Extraction" HeaderText="Extraction" HeaderButtonType="TextButton" DataField="Extraction" UniqueName="Extraction"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Editing" HeaderText="Editing" HeaderButtonType="TextButton" DataField="Editing" UniqueName="Editing"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Publishing" HeaderText="Publishing" HeaderButtonType="TextButton" DataField="Publishing" UniqueName="Publishing"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Pre-Val" HeaderText="Pre-Val" HeaderButtonType="TextButton" DataField="Pre-Val" UniqueName="Pre-Val"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="V & V" HeaderText="V & V" HeaderButtonType="TextButton" DataField="VandV" UniqueName="VandV"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Loco Lab" HeaderText="Loco Lab" HeaderButtonType="TextButton" DataField="LocoLab" UniqueName="LocoLab"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="End 2 End" HeaderText="End 2 End" HeaderButtonType="TextButton" DataField="End 2 End" UniqueName="End2End"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="RSD" HeaderText="RSD" HeaderButtonType="TextButton" DataField="Production" UniqueName="RSD"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Out of Service" HeaderText="Out of Service" HeaderButtonType="TextButton" DataField="Out of Service" UniqueName="OutofService"> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid> <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:PtcDbModelEntities %>" ProviderName="System.Data.SqlClient" SelectCommand=" Select [t0].[SubdivisionId], [t1].[Name] AS Subdivision, [t0].[TrackDatabaseId], [t2].[Description] AS SubStatus, [t0].[Version] AS Version, [t0].[ProposedRevenueServiceDate] AS ProposedRSDDate,(CASE WHEN ( ([t0].[ActualCollectionStartDate] IS NOT NULL) AND ([t0].[ActualCollectionEndDate] IS NULL) ) THEN 'P' WHEN ([t0].[ActualCollectionEndDate] IS NOT NULL) THEN 'C' END) AS 'Collection', (CASE WHEN ( ([t0].[ActualExtractionStartDate] IS NOT NULL) AND ([t0].[ActualExtractionEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualExtractionEndDate] IS NOT NULL) THEN 'C' END) AS 'Extraction', (CASE WHEN ( ([t0].[ActualEditingStartDate] IS NOT NULL) AND ([t0].[ActualEditingEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualEditingEndDate] IS NOT NULL) THEN 'C' END) AS 'Editing', (CASE WHEN ( ([t0].[ActualEditingEndDate] IS NOT NULL) AND ([t0].[ActualVandVStartDate] IS NULL)) THEN 'P' WHEN ( ([t0].[ActualEditingEndDate] IS NOT NULL) AND ([t0].[ActualVandVStartDate] IS NOT NULL) ) THEN 'C' END) AS 'Publishing', (CASE WHEN ( ([t0].[ActualPreValidationStartDate] IS NOT NULL) AND ([t0].[ActualPreValidationEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualPreValidationEndDate] IS NOT NULL) THEN 'C' END) AS 'Pre-Val', (CASE WHEN ( ([t0].[ActualVandVStartDate] IS NOT NULL) AND ([t0].[ActualVandVEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualVandVEndDate] IS NOT NULL) THEN 'C' END) AS 'VandV', (CASE WHEN ( ([t0].[ActualLabTestingStartDate] IS NOT NULL) AND ([t0].[ActualLabTestingEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualLabTestingEndDate] IS NOT NULL) THEN 'C' END) AS 'LocoLab', (CASE WHEN ( ([t0].[ActualE2ERunStartDate] IS NOT NULL) AND ([t0].[ActualE2ERunEndDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualE2ERunEndDate] IS NOT NULL) THEN 'C' END) AS 'End 2 End', (CASE WHEN ( ([t0].[ActualRevenueServiceDate] IS NOT NULL) AND ([t0].[ActualRevenueServiceDate] IS NULL)) THEN 'P' WHEN ([t0].[ActualRevenueServiceDate] IS NOT NULL) THEN 'C' END) AS 'Production' From [PtcDbTracker].[dbo].[TrackDatabase] as [t0] JOIN [PTCDbTracker].[dbo].[Subdivision] as [t1] ON [t0].[SubdivisionId]=[t1].[SubdivisionId] Join [PTCDbTracker].[dbo].[Status] as [t2] ON [t0].[StatusId]=[t2].[StatusId] where [t0].[SubdivisionId] = @SubdivisionId " runat="server"> <SelectParameters> <asp:ControlParameter ControlID="Label1" Name="SubdivisionId" /> </SelectParameters> </asp:SqlDataSource> </telerik:RadPageView> <telerik:RadPageView runat="server" ID="RadPageView3"> <asp:Label ID="Label2" Font-Bold="true" Font-Italic="true" Text='<%# Eval("SubdivisionId") %>' Visible="False" runat="server"></asp:Label> <telerik:RadGrid runat="server" ID="CollectionTab" DataSourceID="SqlDataSource3" ShowFooter="true" AllowSorting="true" EnableLinqExpressions="false" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowAutomaticDeletes="True"> <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true" CommandItemDisplay="None" DataKeyNames="TrackDatabaseId" PageSize="25" HierarchyLoadMode="ServerOnDemand" DataSourceID="SqlDataSource3" EditMode="EditForms"> <Columns> <telerik:GridEditCommandColumn /> <telerik:GridBoundColumn SortExpression="Version" HeaderText="Version" HeaderButtonType="TextButton" DataField="Version" UniqueName="Version"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Status" HeaderText="Status" HeaderButtonType="TextButton" DataField="SubStatus" UniqueName="Status"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="PropCollStart" HeaderText="Proposed Collection Start" HeaderButtonType="TextButton" DataField="PropCollStart" UniqueName="PropCollStart" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="ActCollStart" HeaderText="Actual Collection Start" HeaderButtonType="TextButton" DataField="ActCollStart" UniqueName="ActCollStart" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="PropCollEnd" HeaderText="Proposed Collection End" HeaderButtonType="TextButton" DataField="PropCollEnd" UniqueName="PropCollEnd" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="ActCollEnd" HeaderText="Actual Collection End" HeaderButtonType="TextButton" DataField="ActCollEnd" UniqueName="ActCollEnd" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="PropExtStart" HeaderText="Proposed Extraction Start" HeaderButtonType="TextButton" DataField="PropExtStart" UniqueName="PropExtStart" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="ActCollStart" HeaderText="Actual Extraction Start" HeaderButtonType="TextButton" DataField="ActCollStart" UniqueName="ActCollStart" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="PropExtEnd" HeaderText="Proposed Extraction End" HeaderButtonType="TextButton" DataField="PropExtEnd" UniqueName="PropExtEnd" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="ActExtEnd" HeaderText="Actual Extraction End" HeaderButtonType="TextButton" DataField="ActExtEnd" UniqueName="ActExtEnd" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}"> </telerik:GridBoundColumn> </Columns> <EditFormSettings EditFormType="Template"> <FormTemplate> <table id="table1"> <tr> <td>Collection Details</td> </tr> <tr> <td> <table id="Table2"> <tr> <td> </td> <td>Proposed</td> <td>Actual</td> </tr> <tr> <td>Collection Start Date</td> <td> <telerik:RadDatePicker runat="server" ID="PropCollStart" SelectedDate='<%#Eval("PropCollStart") %>'></telerik:RadDatePicker> </td> <td> <telerik:RadDatePicker runat="server" ID="ActCollStart" SelectedDate='<%#Eval("ActCollStart") %>'></telerik:RadDatePicker> </td> </tr> <tr> <td>Collection End Date</td> <td> <telerik:RadDatePicker runat="server" ID="PropCollEnd" SelectedDate='<%#Eval("PropCollEnd") %>'></telerik:RadDatePicker> </td> <td> <telerik:RadDatePicker runat="server" ID="ActCollEnd" SelectedDate='<%#Eval("ActCollEnd") %>'></telerik:RadDatePicker> </td> </tr> <tr> <td>Extraction Start Date</td> <td> <telerik:RadDatePicker runat="server" ID="PropExtStart" SelectedDate='<%#Eval("PropExtStart") %>'></telerik:RadDatePicker> </td> <td> <telerik:RadDatePicker runat="server" ID="ActExtStart" SelectedDate='<%#Eval("ActExtStart") %>'></telerik:RadDatePicker> </td> </tr> <tr> <td>Extraction End Date</td> <td> <telerik:RadDatePicker runat="server" ID="PropExtEnd" SelectedDate='<%#Eval("PropExtEnd") %>'></telerik:RadDatePicker> </td> <td> <telerik:RadDatePicker runat="server" ID="ActExtEnd" SelectedDate='<%#Eval("ActExtEnd") %>'></telerik:RadDatePicker> </td> </tr> <tr> <td> <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button> <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button> </td> </tr> </table> </td> </tr> </table> </FormTemplate> </EditFormSettings> </MasterTableView> </telerik:RadGrid> <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:PtcDbModelEntities %>" runat="server" ProviderName="System.Data.SqlClient" SelectCommand=" SELECT [t0].[SubdivisionId] , [t1].[Name] AS Subdivision , [t0].[TrackDatabaseId] as TrackDatabaseId , [t2].[Description] AS SubStatus , [t0].[Version] AS Version , [t0].[ProposedCollectionStartDate] AS PropCollStart , [t0].[ActualCollectionStartDate] AS ActCollStart , [t0].[ProposedCollectionEndDate] AS PropCollEnd , [t0].[ActualCollectionEndDate] AS ActCollEnd , [t0].[ProposedExtractionStartDate] AS PropExtStart , [t0].[ActualExtractionStartDate] AS ActExtStart , [t0].[ProposedExtractionEndDate] AS PropExtEnd , [t0].[ActualExtractionEndDate] AS ActExtEnd From [PtcDbTracker].[dbo].[TrackDatabase] as [t0] JOIN [PTCDbTracker].[dbo].[Subdivision] as [t1] ON [t0].[SubdivisionId]=[t1].[SubdivisionId] Join [PTCDbTracker].[dbo].[Status] as [t2] ON [t0].[StatusId]=[t2].[StatusId] where [t0].[SubdivisionId] = @SubdivisionId " UpdateCommand="UPDATE [dbo].[TrackDatabase] SET [ProposedCollectionStartDate] = @PropCollStart , [ActualCollectionStartDate] = @ActCollStart , [ProposedCollectionEndDate] = @PropCollEnd , [ActualCollectionEndDate] = @ActCollEnd , [ProposedExtractionStartDate] = @PropExtStart , [ActualExtractionStartDate] = @ActExtStart , [ProposedExtractionEndDate] = @PropExtEnd , [ActualExtractionEndDate] = @ ActExtEnd WHERE [TrackDatabaseId] = @TrackDatabaseId"> <SelectParameters> <asp:ControlParameter ControlID="Label2" Name="SubdivisionId" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="ProposedCollectionStartDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ActualCollectionStartDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ProposedCollectionEndDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ActualCollectionEndDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ProposedExtractionStartDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ActualExtractionStartDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ProposedExtractionEndDate" Type="DateTime"></asp:Parameter> <asp:Parameter Name="ActualExtractionEndDate" Type="DateTime"></asp:Parameter> </UpdateParameters> </asp:SqlDataSource> </telerik:RadPageView> </telerik:RadMultiPage> </NestedViewTemplate> <Columns> <telerik:GridBoundColumn SortExpression="Subdivision" HeaderText="Subdivision" HeaderButtonType="TextButton" DataField="Subdivision" UniqueName="Subdivision"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Priority" HeaderText="Priority" HeaderButtonType="TextButton" DataField="Priority" UniqueName="Priority"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Mileage" HeaderText="Mileage" HeaderButtonType="TextButton" DataField="Mileage" UniqueName="Mileage"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="Sub Status" HeaderText="Sub Status" HeaderButtonType="TextButton" DataField="SubStatus" UniqueName="SubStatus"> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings AllowDragToGroup="true"> </ClientSettings> </telerik:RadGrid> </div> <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:PtcDbModelEntities %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [t0].[Name] as Subdivision,[t0].[Mileage] AS Mileage,[t0].[SubdivisionId],[t0].[Priority] AS Priority,[t1].[Description] AS SubStatus FROM [PtcDbTracker].[dbo].[Subdivision] as [t0] INNER JOIN [PtcDbTracker].[dbo].[Status] as [t1] on [t0].[StatusId]=[t1].[StatusId] Order By Subdivision" runat="server"></asp:SqlDataSource></asp:Content>And the CodeBehind C#
using System;using System.Web.UI.WebControls;using Telerik.Web.UI;using GridCommandEventArgs = Telerik.Web.UI.GridCommandEventArgs;using GridItemEventArgs = Telerik.Web.UI.GridItemEventArgs;public partial class Default2 : BNSF.EUECommonApplication.EUEBasePage{ public String PageName { get; set; } protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_PreRender(object sender, EventArgs e) { if (!Page.IsPostBack) { RadGrid1.MasterTableView.Items[0].Expanded = false; RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true; } } protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem) { ((GridDataItem)e.Item).ChildItem.FindControl("InnerContainer").Visible = !e.Item.Expanded; } if (e.Item is GridNestedViewItem && e.Item.OwnerTableView.ID == "RadGrid1") { GridNestedViewItem nestedItem = (GridNestedViewItem) e.Item; Panel panel = (Panel) nestedItem.FindControl("InnerContainer"); panel.Visible = ((GridNestedViewItem) e.Item).ParentItem.Expanded; } } protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridNestedViewItem) { e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded; } } protected void RadGrid1_ItemUpdated(object sender, GridUpdatedEventArgs e) { }}