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

RadGrid PerformInsert ItemCommand with CardView (ItemTemplate and EditTemplate)

1 Answer 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 30 Nov 2010, 10:25 AM
else if (e.CommandName == RadGrid.UpdateCommandName)
            {
                MySqlConnection conn = new MySqlConnection();
                conn.ConnectionString = GetConnectionString();
                MySqlCommand cmd = new MySqlCommand();
  
                try
                {
                    GridEditableItem editedItem = e.Item as GridEditableItem;
                    string ID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"].ToString();
  
                    RadNumericTextBox newTimeScaleTextBox = (RadNumericTextBox)e.Item.FindControl("RadNumericBox_TimeScale");
                    string editedTimeScale = newTimeScaleTextBox.Text;
  
                    RadTextBox newGameNameTextBox = (RadTextBox)e.Item.FindControl("RadTextBox_Name");
                    string editedName = newGameNameTextBox.Text;
  
                    RadComboBox newManagerCombo = (RadComboBox)e.Item.FindControl("RadComboBox_Manager");
                    string editedManagerID = newManagerCombo.SelectedValue;
  
                    RadComboBox newRecalibrationDateCombo = (RadComboBox)e.Item.FindControl("RadComboBox_StartPeriod");
                    string editedRecalibrationDate = newRecalibrationDateCombo.SelectedValue;
  
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandText = "MyUpdateSQL" 
                    
cmd.CommandType = CommandType.Text;
  
                    cmd.ExecuteNonQuery();
                }
                catch (MySql.Data.MySqlClient.MySqlException ex)
                {
                    //    IMPLEMENT
                      }  
                conn.Close();
            }


Hi there,

I have a grid setup for cardview with an item template, there is a corresponding edititemtemplate.  The edititemtemplate cointains controls such as a RadNumericTextBox, RadTextBox and a couple of RadComboBoxes (one, crucially, is AutomaticLoadonDemand...this is why I'm not using autogenerated).

The above Item UpdateCommand works great, the values I enter in the edititemtemplate are refelected in the database.   I also conditionally (session variable) have the RadGrid.InsertItem() on page load and this is where the problem starts.

PROBLEM:  I just can't get the PerformInsert command to achieve the same results.  It seems the values i enter on the edititemtemplate are not recoverable from the controls.   I can use FindControl to get for eg RadNumericTextBox newTimeScaleTextBox = (RadNumericTextBox)e.Item.FindControl("RadNumericBox_TimeScale"); 

But when i try and get a value from  newTimeScaleTextBox Text or Value it's empty on the server in the PerformInsert command.

Any help appreciated.
 




 <EditItemTemplate>
  
  
<div style="margin:10px;">
  
  
  <table>
  
    <tr style="height: 50px;">
    <td style="width: 150px; border: none;"><span style="font-weight: bold;">Name:</span></td>
    <td style="border:none;">
      
      
    <telerik:RadTextBox ID="RadTextBox_Name"  EmptyMessage="e.g.  Accounts Department / Q4 2010"  Width="500"  Skin="Office2007" Text='<%# Bind("Name")%>'  runat="server" />
    </td>
      
    </tr>
  
    <tr style="height: 50px;">
    <td style="border:none;"><span style="font-weight: bold;">Start Period:</span></td>
    <td style="border:none;">
      
    <telerik:RadComboBox Width="150" runat="server"  AllowCustomText="true"    DataValueField='<%# Bind("RecalibrationDate") %>' Text='<%# String.Format("{0:MMMM}", Eval("RecalibrationDate")) %>'   Skin="Office2007" ID="RadComboBox_StartPeriod" >
      
    <Items>
      
      
      
    <telerik:RadComboBoxItem Text="January" Value="2010-01-01"   />
    <telerik:RadComboBoxItem Text="February" Value="2010-02-01" />
    <telerik:RadComboBoxItem Text="March" Value="2010-03-01" />
    <telerik:RadComboBoxItem Text="April" Value="2010-04-01" />
    <telerik:RadComboBoxItem Text="May" Value="2010-05-01" />
    <telerik:RadComboBoxItem Text="June" Value="2010-06-01" />
    <telerik:RadComboBoxItem Text="July" Value="2010-07-01" />
    <telerik:RadComboBoxItem Text="August" Value="2010-08-01" />
    <telerik:RadComboBoxItem Text="September" Value="2010-09-01" />
    <telerik:RadComboBoxItem Text="October" Value="2010-10-01" />
    <telerik:RadComboBoxItem Text="November" Value="2010-11-01" />
    <telerik:RadComboBoxItem Text="December" Value="2010-12-01" />
      
    </Items>
      
      
    </telerik:RadComboBox>
  
      
      
      
      
    </td>
      
    </tr>
  
    <tr style="height: 50px;">
    <td style="border:none;"><span style="font-weight: bold;">TimeScale:</span></td>
    <td style="border:none;">
    <telerik:RadNumericTextBox Label="1:" ID="RadNumericBox_TimeScale" Skin="Office2007"  Text='<%# Bind("TimeScale")%>'  MinValue="1" MaxValue="500" NumberFormat-DecimalDigits="0" ShowSpinButtons="true"   runat="server" />
         
    </td>
    </tr>
  
    <tr style="height: 50px;">
    <td style="border:none;"><span style="font-weight: bold;">Manager:</span></td>
    <td style="border:none;"
      
    <telerik:RadComboBox Filter="Contains" AllowCustomText="true" EmptyMessage="Search for a Name and/or Reference"
    EnableVirtualScrolling="true"
    EnableTextSelection="false" 
      
    ShowMoreResultsBox="true"
      
    ItemsPerRequest="20"
    EnableAutomaticLoadOnDemand="true"  
    Skin="Office2007"  Width="300" ID="RadComboBox_Manager" 
    DataSourceID="SqlDataSource_ManagersList" runat="server" 
    DataTextField="DisplayManager" DataValueField="ManagerID" >
    <Items>
      
    </Items>
  
    </telerik:RadComboBox>
  
      
    </td>
    </tr>
  
    <tr style="height: 50px;">
      <td style="border:none;"></td>
      <td style="border:none;">
          
  
  
        <asp:Button ID="Button_InsertUpdate" Text='<%# RadGrid.MasterTableView.IsItemInserted ? "Add" : "Update" %>'
        runat="server" CommandName='<%# RadGrid.MasterTableView.IsItemInserted ? "PerformInsert" : "Update" %>' />
  
          
        <asp:Button ID="Button_DiscardCancel" Text='<%# RadGrid_GameSetup_Basics.MasterTableView.IsItemInserted ? "Discard" : "Cancel" %>'
        runat="server" CommandName='<%# RadGrid_GameSetup_Basics.MasterTableView.IsItemInserted ? "Discard" : "Cancel" %>' />
  
  
  
  
      </td>
    </tr>
      
  </table>
  
    
</div>
</EditItemTemplate>

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 02 Dec 2010, 02:15 PM
Hello Richard,

How do you implement the PerformInsert command? You have shown the UpdateCommand logic, but not the PerformInsert. Is it the same? When using the EditItemTemplate, controls are retrieved in the same manner both for the UpdateCommand and PeformInsert command.


Veli
the Telerik team
Browse the vast support resources we have to jumpstart 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
Richard
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or