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

Edit Form not Displaying

5 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck Lawson
Top achievements
Rank 1
Chuck Lawson asked on 03 Jun 2013, 02:00 PM
I am attempting to put a radgrid that I can edit on a page that contains other other controls (textbox, dropdowns, etc.)
I can get the grid to show but when I click on the edit icon it simply comes back to the same page.
Any help would be appreciated.

The code for the grid is below.
   <!-- RAD Routing GRID -->
        <asp:UpdatePanel ID="upGrid" runat="server">
            <ContentTemplate>
                <table border="0" cellpadding="5" width="100%">
                    <tr>
                        <td valign="top" >
                           <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                                <script type="text/javascript">
                                    function RowDblClick(sender, eventArgs) {
                                        sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                                    }
 
                                    function gridCreated(sender, args) {
                                        if (sender.get_editIndexes && sender.get_editIndexes().length > 0) {
                                            document.getElementById("OutPut").innerHTML = sender.get_editIndexes().join();
                                        }
                                        else {
                                            document.getElementById("OutPut").innerHTML = "";
                                        }
                                    }
                                </script>
                            </telerik:RadCodeBlock>
                            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                                <AjaxSettings>
                                    <telerik:AjaxSetting AjaxControlID="gvEdit">
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="gvEdit" LoadingPanelID="pnlLoad">
                                            </telerik:AjaxUpdatedControl>
                                            <telerik:AjaxUpdatedControl ControlID="winManager"></telerik:AjaxUpdatedControl>
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                </AjaxSettings>
                            </telerik:RadAjaxManager>
                            <telerik:RadAjaxLoadingPanel ID="pnlLoad" runat="server"></telerik:RadAjaxLoadingPanel>
                            <telerik:RadGrid ID="gvEdit" GridLines="None" runat="server" Skin="WebBlue"   AllowAutomaticDeletes="True"
                                AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" AllowPaging="True"
                                AutoGenerateColumns="False" DataSourceID="sdsEditGrid" OnItemUpdated="gvEdit_ItemUpdated"
                                OnItemDeleted="gvEdit_ItemDeleted" OnItemInserted="gvEdit_ItemInserted" OnItemCreated="gvEdit_ItemCreated"
                                OnItemCommand="gvEdit_ItemCommand" OnDataBound="gvEdit_DataBound">
                                <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                                <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="RoutingID"
                                    DataSourceID="sdsEditGrid" HorizontalAlign="NotSet" AutoGenerateColumns="False">
                                    <Columns>
                                        <%-- Edit Image--%>
                                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                                            <ItemStyle CssClass="MyImageButton"></ItemStyle>
                                        </telerik:GridEditCommandColumn>
 
                                        <%--Name DropDown--%>
                                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name"
                                            SortExpression="Name" UniqueName="Name" Visible="true"
                                            EditFormColumnIndex="0" ColumnEditorID="GridTextBoxColumnEditor1" MaxLength="50">
                                        </telerik:GridBoundColumn>
 
                                         <%--RoutingID TextBox--%>
                                        <telerik:GridBoundColumn DataField="RoutingID" HeaderText="RoutingID"
                                            SortExpression="RID" UniqueName="RID" Visible="true"
                                            EditFormColumnIndex="0" ColumnEditorID="GridTextBoxColumnEditor0" MaxLength="50">
                                        </telerik:GridBoundColumn>
 
                                         <%--Department DropDown--%>
                                        <telerik:GridBoundColumn DataField="Department_Code" HeaderText="Department"
                                            SortExpression="Department" UniqueName="Department" Visible="true"
                                            EditFormColumnIndex="1" ColumnEditorID="GridTextBoxColumnEditor2" MaxLength="50"  >
                                        </telerik:GridBoundColumn>
 
                                         <%--Date Sent TextBox--%>
                                       <%-- <telerik:GridBoundColumn DataField="DateSent" HeaderText="Date Sent"
                                            SortExpression="DateSent" UniqueName="DateSent" Visible="true"
                                            EditFormColumnIndex="2" ColumnEditorID="GridTextBoxColumnEditor3" MaxLength="50">
                                        </telerik:GridBoundColumn>--%>
 
                                         <%--Date Returned TextBox--%>
                                       <%-- <telerik:GridBoundColumn DataField="DateReturned" HeaderText="Date Returned"
                                            SortExpression="DateReturned" UniqueName="DateReturned" Visible="true"
                                            EditFormColumnIndex="3" ColumnEditorID="GridTextBoxColumnEditor4" MaxLength="50">
 
                                        </telerik:GridBoundColumn>--%>
                                          <%--Inactive checkbox--%>
                                       <%-- <telerik:GridCheckBoxColumn DataField="InActive" HeaderText="InActive" SortExpression="InActive"
                                            UniqueName="InActive" EditFormColumnIndex="0" >
                                        </telerik:GridCheckBoxColumn>--%>
                                          <%--Delete --%>
                                        <telerik:GridButtonColumn ConfirmText="Delete this Routing Record?" ConfirmDialogType="RadWindow"
                                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                                            UniqueName="DeleteColumn">
                                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                                        </telerik:GridButtonColumn>
                                    </Columns>
 
                                    <EditFormSettings  ColumnNumber="1" CaptionDataField="RoutingID" CaptionFormatString="Edit Routing Record: {0}"
                                        InsertCaption="New Routing Record" FormCaptionStyle-Font-Bold="true" FormMainTableStyle-BackColor="lightgrey" >
                                        <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                                        <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                                        <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%"></FormMainTableStyle>
                                        <FormTableStyle CellSpacing="0" CellPadding="2" Height="40px"></FormTableStyle>
                                        <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                        <EditColumn ButtonType="ImageButton" InsertText="Insert Routing Record" UpdateText="Update record"
                                            UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                                        </EditColumn>
                                        <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                                    </EditFormSettings>
 
                                </MasterTableView>
 
                                <ClientSettings>
                                    <ClientEvents OnRowDblClick="RowDblClick" OnGridCreated="gridCreated"></ClientEvents>
                                </ClientSettings>
                                </telerik:RadGrid>
                                <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="100px"/>
                                <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor2" runat="server" TextBoxStyle-Width="350px"/>
 
                            <br />
                          
                            <asp:SqlDataSource 
                             ID="sdsEditGrid" 
                             runat="server"
                             SelectCommand ="usp_Get_Routing_ForBulletin"
                             InsertCommand="dbsp_addCompany"
                             UpdateCommand="dbsp_updateCompanies"
                             DeleteCommand="dbsp_deleteCompany"
                             SelectCommandType="StoredProcedure"
                             InsertCommandType="StoredProcedure"
                             UpdateCommandType="StoredProcedure"
                             DeleteCommandType="StoredProcedure" >
 
                             <SelectParameters>
                                <asp:Parameter Name="BulletinNumber" Type="Int32"  />
                             </Selectparameters>   
 
                            <InsertParameters>
                            
                            </InsertParameters>
 
                            <UpdateParameters>
                                <asp:Parameter Name="RoutingID" Type="Int32"  />
                            </UpdateParameters>
 
                            <DeleteParameters>
                                <asp:Parameter Name="RoutingID" Type="Int32"  />
                            </DeleteParameters>
 
                        </asp:SqlDataSource
                       </td>
                    </tr>
                </td>
        </table>
     </td>
  </tr>
</table>
            </ContentTemplate>
        </asp:UpdatePanel>
 

Code from .cs file pertaining to radgrid edit

 

protected void gvEdit_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)

{

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

{

 

GridEditableItem item1 = e.Item as GridEditableItem;

 

GridTextBoxColumnEditor editor1 = (GridTextBoxColumnEditor)item1.EditManager.GetColumnEditor("Name");

 

TableCell cell1 = (TableCell)editor1.TextBoxControl.Parent;

 

RequiredFieldValidator validator1 = new RequiredFieldValidator();

editor1.TextBoxControl.ID =

 

"Namex";

validator1.ControlToValidate = editor1.TextBoxControl.ID;

validator1.ErrorMessage =

 

"Name required";

cell1.Controls.Add(validator1);

 

GridEditableItem item2 = e.Item as GridEditableItem;

 

GridTextBoxColumnEditor editor2 = (GridTextBoxColumnEditor)item2.EditManager.GetColumnEditor("Department");

 

TableCell cell2 = (TableCell)editor2.TextBoxControl.Parent;

 

RequiredFieldValidator validator2 = new RequiredFieldValidator();

editor2.TextBoxControl.ID =

 

"Name_for_validation";

validator2.ControlToValidate = editor2.TextBoxControl.ID;

validator2.ErrorMessage =

 

"Department required";

cell2.Controls.Add(validator2);

}

}

 

protected void gvEdit_ItemUpdated(object source, GridUpdatedEventArgs e)

{

 

if (e.Exception != null)

{

e.KeepInEditMode =

 

true;

e.ExceptionHandled =

 

true;

SetMessage(

 

"Routing record not updated. Reason: " + e.Exception.Message);

}

 

else

{

gvEdit.Rebind();

SetMessage(

 

"Routing record updated!");

}

}

 

protected void gvEdit_ItemDeleted(object source, GridDeletedEventArgs e)

{

 

if (e.Exception != null)

{

e.ExceptionHandled =

 

true;

 

String x = "Routing Record cannot be deleted. Reason: " + e.Exception.Message;

DisplayMessage(x);

}

 

else

{

gvEdit.Rebind();

SetMessage(

 

"Company is deleted!");

}

}

 

protected void gvEdit_ItemInserted(object source, GridInsertedEventArgs e)

{

 

if (e.Exception != null)

{

e.KeepInInsertMode =

 

true;

e.ExceptionHandled =

 

true;

 

String x = "Routing Record cannto be inserted. Reason: " + e.Exception.Message;

DisplayMessage(x);

}

 

else

{

SetMessage(

 

"New Routing Record is inserted!");

gvEdit.Rebind();

}

}

 

protected void gvEdit_ItemCommand(object source, GridCommandEventArgs e)

{

 

if (e.CommandName == RadGrid.EditCommandName)

{

gvEdit.MasterTableView.IsItemInserted =

 

false;

}

 

if (e.CommandName == RadGrid.InitInsertCommandName)

{

gvEdit.MasterTableView.ClearEditItems();

}

}

 

protected void gvEdit_DataBound(object sender, EventArgs e)

{

 

if (!string.IsNullOrEmpty(gridMessage))

{

DisplayMessage(gridMessage);

}

}

Some of the code from the .cs file pertaining to the radgrid edit

protected void gvEdit_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem item1 = e.Item as GridEditableItem;
           GridTextBoxColumnEditor editor1 = (GridTextBoxColumnEditor)item1.EditManager.GetColumnEditor("Name");
           TableCell cell1 = (TableCell)editor1.TextBoxControl.Parent;
           RequiredFieldValidator validator1 = new RequiredFieldValidator();
           editor1.TextBoxControl.ID = "Namex";
           validator1.ControlToValidate = editor1.TextBoxControl.ID;
           validator1.ErrorMessage = "Name required";
           cell1.Controls.Add(validator1);
 
           GridEditableItem item2 = e.Item as GridEditableItem;
           GridTextBoxColumnEditor editor2 = (GridTextBoxColumnEditor)item2.EditManager.GetColumnEditor("Department");
           TableCell cell2 = (TableCell)editor2.TextBoxControl.Parent;
           RequiredFieldValidator validator2 = new RequiredFieldValidator();
           editor2.TextBoxControl.ID = "Name_for_validation";
           validator2.ControlToValidate = editor2.TextBoxControl.ID;
           validator2.ErrorMessage = "Department required";
           cell2.Controls.Add(validator2);
       }
   }
   protected void gvEdit_ItemUpdated(object source, GridUpdatedEventArgs e)
   {
       if (e.Exception != null)
       {
           e.KeepInEditMode = true;
           e.ExceptionHandled = true;
           SetMessage("Routing record  not updated. Reason: " + e.Exception.Message);
       }
       else
       {
           gvEdit.Rebind();
           SetMessage("Routing record updated!");
 
       }
   }
   protected void gvEdit_ItemDeleted(object source, GridDeletedEventArgs e)
   {
       if (e.Exception != null)
       {
           e.ExceptionHandled = true;
           String x = "Routing Record cannot be deleted. Reason: " + e.Exception.Message;
           DisplayMessage(x);
       }
       else
       {
           gvEdit.Rebind();
           SetMessage("Company is deleted!");
       }
   }
   protected void gvEdit_ItemInserted(object source, GridInsertedEventArgs e)
   {
       if (e.Exception != null)
       {
           e.KeepInInsertMode = true;
           e.ExceptionHandled = true;
           String x = "Routing Record cannto be inserted. Reason: " + e.Exception.Message;
           DisplayMessage(x);
       }
       else
       {
           SetMessage("New Routing Record is inserted!");
           gvEdit.Rebind();
       }
   }
   protected void gvEdit_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.EditCommandName)
       {
           gvEdit.MasterTableView.IsItemInserted = false;
       }
 
       if (e.CommandName == RadGrid.InitInsertCommandName)
       {
           gvEdit.MasterTableView.ClearEditItems();
       }
   }
   protected void gvEdit_DataBound(object sender, EventArgs e)
   {
       if (!string.IsNullOrEmpty(gridMessage))
       {
           DisplayMessage(gridMessage);
       }
   }

5 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 03 Jun 2013, 05:09 PM
um - I could be wrong on this but.... have you specified an EditMode? (InPlace, Popup, etc)
0
Chuck Lawson
Top achievements
Rank 1
answered on 03 Jun 2013, 07:25 PM
I added

EditMode="EditForms" and I tried "PopUp" in MasterTableView
It still simply refreshes and does not go to edit mode.

 

 

 

0
Elliott
Top achievements
Rank 2
answered on 03 Jun 2013, 07:30 PM
Chuck - it's not there now

<MasterTableViewWidth="100%"CommandItemDisplay="TopAndBottom"DataKeyNames="RoutingID"
    DataSourceID="sdsEditGrid"HorizontalAlign="NotSet"AutoGenerateColumns="False">
0
Chuck Lawson
Top achievements
Rank 1
answered on 03 Jun 2013, 07:57 PM

My latest attempt - still not working - same issue

<telerik:RadGrid ID="gvEdit" GridLines="None" runat="server" Skin="WebBlue"   AllowAutomaticDeletes="True"
                                AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" AllowPaging="True"
                                AutoGenerateColumns="False" DataSourceID="sdsEditGrid" OnItemUpdated="gvEdit_ItemUpdated"
                                OnItemDeleted="gvEdit_ItemDeleted" OnItemInserted="gvEdit_ItemInserted" OnItemCreated="gvEdit_ItemCreated"
                                OnItemCommand="gvEdit_ItemCommand" OnDataBound="gvEdit_DataBound">
                                <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                                <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="RoutingID"
                                    DataSourceID="sdsEditGrid" HorizontalAlign="NotSet" AutoGenerateColumns="False" EditMode="EditForms">
0
Elliott
Top achievements
Rank 2
answered on 03 Jun 2013, 08:16 PM
and you have a CommandItemDisplay set correctly...

I can't help you any more - I do all but the simplest I/O on the server - and in that case I would put a debug stop on my NeedDataSource
I suspect you are refreshing the grid at the wrong time, but I honestly don't know how to debug a process happening through a DataSource object

sorry :(
Tags
Grid
Asked by
Chuck Lawson
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Chuck Lawson
Top achievements
Rank 1
Share this question
or