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

Won't go into edit mode after insert

4 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 29 Jul 2011, 04:12 PM
I have a RadGrid within a RadWindow. The Grid actually lives in a separate ASPX file that is called into the RadWindow. The issue I'm having is that once I go into insert mode I can't go into edit mode unless I close my RadWindow and reopen it. If I choose edit mode first I have no issues. It only happens after I go into insert mode at any point, even if I don't actually insert a record.

On a side note I also have the issue that my insert popup window won't close after clicking the "Save" button.

Below is my code:

ASPX

<telerik:RadAjaxLoadingPanel ID="editDetailsLoadingPanel" runat="server" Skin="Vista" Transparency="30" />
<telerik:RadAjaxPanel ID="editDetailsPanel" runat="server" LoadingPanelID="editDetailsLoadingPanel">
                    <table>
                        <tr>
                            <td><asp:Label ID="editDetailsCostCtrLbl" Text="Cost Center:" runat="server" /></td>
                            <td><telerik:RadTextBox ID="editDetailsCostCtrTxt" runat="server" EmptyMessage="Enter Cost Center"/></td>
                        </tr>
                        <tr>
                            <td><asp:Label ID="editDetailsAuxLocLbl" Text="Aux Location: " runat="server" /></td>
                            <td><telerik:RadTextBox ID="editDetailsAuxLocTxt" runat="server" EmptyMessage="Enter Aux Location"/></td>
                        </tr>
                        <tr>
                            <!-- START PAR VALUE REGION -->
                            <td colspan="2">
                                <asp:Label ID="editDetailsParValueGridLbl" Text="Set Par Values" runat="server" />
                                <telerik:RadGrid ID="itemsParValueGrid" runat="server" AutoGenerateColumns="false" AllowPaging="true" Width="500px"
                                OnNeedDataSource="itemsParValueGrid_NeedDataSource" OnItemCommand="itemsParValueGrid_ItemCommand" AllowAutomaticUpdates="false" AllowAutomaticInserts="false">
                                    <MasterTableView CommandItemDisplay="Top" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true">
                                        <NoRecordsTemplate>
                                            <div>There are no records to display</div>
                                        </NoRecordsTemplate>
                                        <Columns>
                                            <telerik:GridEditCommandColumn />
                                            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" Visible="false" />
                                            <telerik:GridBoundColumn UniqueName="Description" DataField="Description" HeaderText="Description" ReadOnly="true" />
                                            <telerik:GridBoundColumn UniqueName="PSNum" DataField="PSNum" HeaderText="PS #" ReadOnly="true"/>
                                            <telerik:GridBoundColumn UniqueName="Min" DataField="Min" HeaderText="Min" />
                                            <telerik:GridBoundColumn UniqueName="Max" DataField="Max" HeaderText="Max"  />
                                        </Columns>
                                        <EditFormSettings EditFormType="Template">
                                             <FormTemplate>
                                                <table>
                                                    <tr>
                                                        <td colspan="2">
                                                            <telerik:RadTextBox ID="parValueFilterTxt" EmptyMessage="Search PS # ..." runat="server" Width="200px" ClientEvents-OnKeyPress="filterList" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <telerik:RadListBox ID="RadListBox1" runat="server" AllowTransfer="true" Height="200px" Width="230px" SelectionMode="Multiple" TransferToID="RadListBoxTransfer" OnClientDropped="OnClientDroppedHandler" OnDeleted="RadListBox1_ItemDeleted" AutoPostBackOnTransfer="true"/>
                                                        </td>
                                                        <td>
                                                            <telerik:RadListBox ID="RadListBoxTransfer" runat="server" Height="200px" Width="200px" SelectionMode="Multiple" OnLoad="listboxload" OnDeleted="RadListBoxTransfer_ItemDeleted"/>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2">
                                                            <telerik:RadButton ID="ParValueListBoxBtn" runat="server" Text="Save" CommandName="Save" />
                                                        </td>
                                                    </tr>
                                               </table>
 
                                            </FormTemplate>
                                        </EditFormSettings>
                                        <CommandItemSettings ShowRefreshButton="false" />
                                    </MasterTableView>
                                </telerik:RadGrid>
                            </td>
                            <!-- END PAR VALUE REGION -->
                        </tr>
                        <tr>
                            <td colspan="2"><telerik:RadButton ID="editDetailsUpdateBtn" runat="server" Text="Update" OnClick="editDetailsUpdateBtn_Click" AutoPostBack="true" /></td>
                        </tr>
                    </table>
</telerik:RadAjaxPanel>


C#


       private static List<string> addedParValue;
       private static List<string> removedParValue;
 
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               editDetailsAuxLocTxt.Text = AssetWhere.Admin_new.editDetailsAuxLoc;
               editDetailsCostCtrTxt.Text = AssetWhere.Admin_new.editDetailsCostCtr;
           }
       }
 
       protected void editDetailsUpdateBtn_Click(object sender, EventArgs e)
       {
           string AuxLocation = editDetailsAuxLocTxt.Text;
           string CostCenter = editDetailsCostCtrTxt.Text;
           string LocationID = AssetWhere.Admin_new.editDetailsLocationID;
 
           SqlCommand editDetailsUpdateCmd = new SqlCommand("UPDATE dbo.locations SET CostCenter='" + CostCenter + "', AuxLocationID='" + AuxLocation + "' WHERE ID ='" + LocationID + "'", connection);
           connection.Open();
           editDetailsUpdateCmd.ExecuteNonQuery();
           connection.Close();
 
       }
 
       protected void itemsParValueGrid_NeedDataSource(object sender, EventArgs e)
       {
           // Bind the Location Par Value Grid
           itemsParValueGrid.DataSource = GetDataTable("SELECT ItemParValues.ID, items.Description,items.CrossRefID as [PSNum],ItemParValues.Min,ItemParValues.Max FROM dbo.ItemParValues INNER JOIN dbo.items ON items.ID = ItemParValues.ItemID WHERE ItemParValues.LocationID = '" + AssetWhere.Admin_new.editDetailsLocationID + "' AND items.Tracking='1' ORDER BY [Min] ASC, [MAX] ASC, [PSNum] ASC");
       }
 
       public DataTable GetDataTable(string queryString)
       {
           using (SqlCommand cmd = new SqlCommand(queryString, connection))
           {
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataTable dt = new DataTable();
               da.Fill(dt);
 
               return dt;
           }
       }
 
       protected void listboxload(object sender, EventArgs e)
       {
           // Search for controls
           RadListBox rlbSource = (RadListBox)((GridItem)((Control)sender).NamingContainer).FindControl("RadListBox1");
           RadListBox rlbDest = (RadListBox)((GridItem)((Control)sender).NamingContainer).FindControl("RadListBoxTransfer");
           RadTextBox txt = (RadTextBox)((GridItem)((Control)sender).NamingContainer).FindControl("parValueFilterTxt");
 
           // Command for getting the source and dest PS Numbers
           SqlCommand getSourcePSNum = new SqlCommand("SELECT items.CrossRefID, items.ID FROM dbo.items WHERE Tracking='1' AND CrossRefID NOT IN (SELECT items.CrossRefID FROM dbo.items inner join dbo.ItemParValues on items.ID = ItemParValues.ItemID WHERE ItemParValues.LocationID='" + AssetWhere.Admin_new.editDetailsLocationID + "' AND items.Tracking='1') ORDER BY items.CrossRefID ASC", connection);
           SqlCommand getDestPSNum = new SqlCommand("SELECT items.CrossRefID, items.ID FROM dbo.items inner join dbo.ItemParValues on items.ID = ItemParValues.ItemID WHERE ItemParValues.LocationID='" + AssetWhere.Admin_new.editDetailsLocationID + "' AND items.Tracking='1' ORDER BY items.CrossRefID ASC", connection);
 
           // Add Source PS Numbers to ListBox
           connection.Open();
               SqlDataReader sourceRdr = getSourcePSNum.ExecuteReader();
               while (sourceRdr.Read())
               {
                   rlbSource.Items.Add(new RadListBoxItem(sourceRdr.GetString(0), sourceRdr.GetGuid(1).ToString()));
               }
               sourceRdr.Close();
 
               // Add Dest PS Numbers to ListBox
               SqlDataReader destRdr = getDestPSNum.ExecuteReader();
               while (destRdr.Read())
               {
                   rlbDest.Items.Add(new RadListBoxItem(destRdr.GetString(0), destRdr.GetGuid(1).ToString()));
               }
               destRdr.Close();
           connection.Close();
 
           // Register Javascript for the TextBox
           string script = "var listbox;var filterTextBox;function pageLoad(){listbox = $find('" + rlbSource.ClientID  + "');filterTextBox = document.getElementById('" + txt.ClientID + "');listbox._getGroupElement().focus();}function OnClientDroppedHandler(sender, eventArgs){eventArgs.get_sourceItem().set_text(clearTextEmphasis(eventArgs.get_sourceItem().get_text()));}function filterList(){clearListEmphasis();createMatchingList();}function clearListEmphasis(){var re = new RegExp('</{0,1}em>', 'gi');var items = listbox.get_items();var itemText;items.forEach(function(item){itemText = item.get_text();item.set_text(clearTextEmphasis(itemText));})}function clearTextEmphasis(text){var re = new RegExp('</{0,1}em>', 'gi');return text.replace(re, '');}function createMatchingList(){var items = listbox.get_items();var filterText = filterTextBox.value;var re = new RegExp(filterText, 'i');items.forEach(function(item){var itemText = item.get_text();if (itemText.toLowerCase().indexOf(filterText.toLowerCase()) != -1){item.set_text(itemText.replace(re, '<em>' + itemText.match(re) + '</em>'));item.set_visible(true);}else{item.set_visible(false);}})}";
           ScriptManager.RegisterStartupScript(this, this.GetType(), "key22", script, true);
       }
 
       protected void itemsParValueGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
       {
           if (e.CommandName == RadGrid.InitInsertCommandName)
           {
               e.Item.OwnerTableView.EditMode = GridEditMode.PopUp;
               e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Modal = true;
               e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Width = 500;
               e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Height = 300;
               e.Item.OwnerTableView.EditFormSettings.InsertCaption = "Add/Remove Item ParValue Tracking";
           }
           else if (e.CommandName == RadGrid.EditCommandName)
           {
               e.Item.OwnerTableView.EditMode = GridEditMode.InPlace;
           }
           else if (e.CommandName == RadGrid.UpdateCommandName)
           {
               GridEditableItem editedItem = e.Item as GridEditableItem;
 
               TextBox parValueDescription = (TextBox)editedItem["Description"].Controls[0];
               TextBox parValuePSNum = (TextBox)editedItem["PSNum"].Controls[0];
               TextBox parValueMin = (TextBox)editedItem["Min"].Controls[0];
               TextBox parValueMax = (TextBox)editedItem["Max"].Controls[0];
               TextBox parValueID = (TextBox)editedItem["ID"].Controls[0];
 
               SqlCommand updateParValues = new SqlCommand("UPDATE dbo.ItemParValues SET Min='" + parValueMin.Text + "', Max='" + parValueMax.Text + "' WHERE ID='" + parValueID.Text + "' AND LocationID='" + AssetWhere.Admin_new.editDetailsLocationID + "'", connection);
 
               connection.Open();
               updateParValues.ExecuteNonQuery();
               connection.Close();
           }
 
           else if (e.CommandName == "Save")
           {
               // Set variables
               int i = 0;
               int x = 0;
               Guid ParValueID = new Guid();
 
               // Setup search
               GridEditableItem editedItem = e.Item as GridEditableItem;
 
               RadListBox rlbSource = (editedItem.FindControl("RadListBox1") as RadListBox);
               RadListBox rlbDest = (editedItem.FindControl("RadListBoxTransfer") as RadListBox);
 
               while (addedParValue != null && i < addedParValue.Count())
               {
                   ParValueID = Guid.NewGuid();
 
                   // Insert new parvalues
                   connection.Open();
                   SqlCommand insertParValues = new SqlCommand("INSERT INTO dbo.ItemParValues (ID, LocationID, ItemID, CriticalLevel, Min, Max) VALUES ('" + ParValueID.ToString() + "', '" + AssetWhere.Admin_new.editDetailsLocationID + "', '" + addedParValue[i] + "', '0', '0', '0')", connection);
                   insertParValues.ExecuteNonQuery();
                   connection.Close();
                   i++;
               }
 
               while (removedParValue != null && x < removedParValue.Count())
               {
                   connection.Open();
                   // Remove old parvalues
                   SqlCommand deleteParValues = new SqlCommand("DELETE FROM dbo.ItemParValues WHERE ItemID='" + removedParValue[x] + "' AND LocationID='" + AssetWhere.Admin_new.editDetailsLocationID + "'", connection);
                   deleteParValues.ExecuteNonQuery();
                   connection.Close();
                   x++;
               }
 
 
                
           }
       }
 
       protected void RadListBox1_ItemDeleted(object sender, RadListBoxEventArgs e)
       {
           // Initialize List
           addedParValue = new List<string>();
           removedParValue = new List<string>();
 
           // Clear list so we can start fresh
           addedParValue.Clear();
 
           // Add all inserted items to list
           foreach (RadListBoxItem item in e.Items)
           {
               // Check to see if it already exists in the list
               if (!addedParValue.Contains(item.Value.ToString()))
                   addedParValue.Add(item.Value.ToString());
 
               // Remove the value if it exists in the source list
               // needed if you move a value back and forth in one session
               if (removedParValue.Contains(item.Value.ToString()))
                   removedParValue.Remove(item.Value.ToString());
           }
       }
 
       protected void RadListBoxTransfer_ItemDeleted(object sender, RadListBoxEventArgs e)
       {
           // Initialize List
           addedParValue = new List<string>();
           removedParValue = new List<string>();
 
           // Clear list so we can start fresh
           removedParValue.Clear();
 
           // Add all inserted items to list
           foreach (RadListBoxItem item in e.Items)
           {
               // Check to see if it already exists in the list
               if (!removedParValue.Contains(item.Value.ToString()))
                   removedParValue.Add(item.Value.ToString());
 
               // Remove the value if it exists in the source list
               // needed if you move a value back and forth in one session
               if (addedParValue.Contains(item.Value.ToString()))
                   addedParValue.Remove(item.Value.ToString());
           }
       }
   }


Any help is greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
William
Top achievements
Rank 1
answered on 01 Aug 2011, 03:43 PM
If I change the RadAjaxPanel to an ASP Panel, add a RadAjaxManger, and move the RadScriptManager below it, then everything works, except I don't get a loading animation. Not quite sure why this is.

ASPX

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="editDetailsPanel">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="editDetailsPanel" LoadingPanelID="editDetailsLoadingPanel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePartialRendering="true" LoadScriptsBeforeUI="false"></telerik:RadScriptManager>
0
Pavlina
Telerik team
answered on 04 Aug 2011, 10:01 AM
Hi William,

Please try to place the RadScriptManager control before the RadAjaxManager on the page and see if it makes any difference. Additionally, what happens if you remove the Transparency setting from the RadAjaxLoadingPanel?

Greetings,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
William
Top achievements
Rank 1
answered on 04 Aug 2011, 02:38 PM
Placing the RadScriptManager first will display the loading panel, but if I go into Insert mode, Cancel out of Insert mode, and then try to Edit an item, the loading animation displays indefinitely. Removing the transparency has no effect on this error. 

Here is a video showing what I mean:
http://www.screencast.com/t/Uzs4s1RhCTJu
0
Pavlina
Telerik team
answered on 09 Aug 2011, 03:32 PM
Hello William,

If the issue persists it will be best to send us sample runnable application which demonstrates the erroneous behaviour. Thus we will be able to inspect it locally and advise you further.

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
William
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or