get value on insert

8 posts, 0 answers
  1. Lee Malo
    Lee Malo avatar
    29 posts
    Member since:
    Apr 2008

    Posted 15 Oct 2009 Link to this post

    I need to access a value that is common to all rows when I run the insert command. How is the best way to accomplish this?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Oct 2009 Link to this post

    Hi Lee Malo,

    I suppose you are trying to access a cell value which is common to all rows in the InsertCommand. If so, you can try out the following code:
    c#:
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
        {         
            GridEditableItem item = (GridEditableItem)e.Item; 
            string strtxt = item.OwnerTableView.Items[0]["ColumnUniqueName"].Text; 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 15 Oct 2009 Link to this post

    So, how do you get the item.cell().text that is actually being INSERTED (not edited)?  All I get are empty strings.  Nada.  Nothing.  And the documentation really sucks and offers nothing for people using object data sources.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Oct 2009 Link to this post

    Hello Mark,

    To access a the text that is currently being inserted from the insert form in the InsertCommand, you would have to access the textbox control(for bound columns) first and then access the text as shown below:
    c#:
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
        {        
            GridEditableItem item = (GridEditableItem)e.Item; 
             
            TextBox txtbx = (TextBox)item["BoundColumnUniqueName"].Controls[0]; 
            string strtxt1 = txtbx.Text; 
        } 

    Thanks
    Princy.
  6. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 16 Oct 2009 Link to this post

    Hello Princy,

    Your C# example is just another reiteration of the same code posted in the VB examples and does not work.  I continue to get empty strings returned from the INSERT textboxes.
    Protected Sub radGrid2_InsertCommand( sender As Object, e As GridCommandEventArgs ) Handles radGrid2.InsertCommand  
     
    Dim v_item As GridDataItem = CType( e.Item, GridDataItem )  
    Dim depot_cost As String = CType( v_item( "depot_reset_cost" ).Controls( 0 ), TextBox ).Text  
    RadAjaxManager1.Alert( "depot_cost=" & depot_cost ) 

    Mark
  7. Mark Breen
    Mark Breen avatar
    23 posts
    Member since:
    Oct 2009

    Posted 18 Oct 2009 Link to this post

    Hello All,

    I tried this code and it works for me, however, I cannot get it to work in Edit mode, spent four hours trying to get it to work yesterday,

    Here is the code that does work.

            protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
            { 
                GridEditableItem item = (GridEditableItem)e.Item; 
     
                TextBox LastModifiedByIPAddress = (TextBox)item["LastModifiedByIPAddress"].Controls[0]; 
                LastModifiedByIPAddress.Text = GetIPAddress(); 
     
      
            } 
     

    and then I have tried a hundred variations on the following but cannot get it to work.  Thanks in advance for any suggestions.

            protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e) 
            { 
                GridEditableItem item = (GridEditableItem)e.Item; 
     
                TextBox LastModifiedByIPAddress = (TextBox)item["LastModifiedByIPAddress"].Controls[0]; 
                LastModifiedByIPAddress.Text = GetIPAddress(); 
            } 
     


    Mark Breen
    Ireland

  8. Joao Araujo
    Joao Araujo avatar
    16 posts
    Member since:
    Aug 2009

    Posted 18 Oct 2009 Link to this post

    Hello Mark,


         I think I have had the same problems you had. Here is how I solved my problem. 
         Nothing that I did made it to work with InsertCommand, and UpdateCommand
         
         As you will see I edit the sources here and there to cut down the size a little bit. 
        1. I  Created a popup form to edit, insert the item 
     
                     <EditFormSettings EditFormType="Template" CaptionFormatString="Bank Transaction Input"
                            PopUpSettings-Modal="true" PopUpSettings-Width="300px">
                            <FormTemplate>
                                                <span class="title">TransactionTypeID</span>
                                                <Telerik:RadComboBox ID="TransactionTypeID" DataSourceID="TransactionTypesDS" AppendDataBoundItems="true"
                                                    DataTextField="Description" DataValueField="TransactionTypeID" SelectedValue='<%# Bind("TransactionTypeID") %>'
                                                    runat="server">
                                                </Telerik:RadComboBox>

                                                <span class="title">Amount</span>
                                                <Telerik:RadNumericTextBox ID="Amount" Text='<%# Bind( "Amount") %>' runat="server"
                                                    NumberFormat-DecimalDigits="2">
                                                </Telerik:RadNumericTextBox>

                                                <span class="title">Date</span>
                                                <Telerik:RadTextBox ID="TrnDate" runat="server" Skin="Forest" Text='<%# Bind("TrnDate") %>'>
                                                </Telerik:RadTextBox>
                                                <span style="color: Red">*</span>

        2. I added the following logic on the item command logic
    protected void TransactionsGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
            {
             if (e.CommandName == RadGrid.InitInsertCommandName)
                {
                     // Adding default values to the items
                    e.Canceled = true;
                    //Prepare an IDictionary with the predefined values
                    ListDictionary newValues = new ListDictionary();
                    newValues["TrnDate"] = DateTime.Now.ToString("d");
                    //Insert the item and rebind
                    e.Item.OwnerTableView.InsertItem(newValues);
                }
                if (e.CommandName == RadGrid.PerformInsertCommandName)
                {
                   // Performing the insert
                          GridEditableItem editedItem = e.Item as GridEditableItem;
                        Hashtable newValues = new Hashtable();
                        //The GridTableView will fill the values from all editable columns in the hash
                         e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                    try
                    {
                        transaction.Amount = Convert.ToSingle(newValues["Amount"]);
                        transaction.TransactionTypeID = Convert.ToInt32(newValues["TransactionTypeID"]);
                        transaction.TrnDate = Convert.ToDateTime(newValues["TrnDate"]);
                        accounts[0].AddTransaction(transaction);
                        dao.SaveOrUpdate(accounts[0]);

                    }


        Hope that helps

    John,
  9. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 19 Oct 2009 Link to this post

    Thanks for the example, John.  I had already implemented a custom solution myself along similar logic as you.

    However, and this must me emphasized, I DID NOT PAY $800 FRIGGIN' DOLLARS TO IMPLEMENT CODE I WOULD HAVE DONE FOR FREE.  What the #@$! did I pay Telerik $800 for????  All I have received from them are repeated references to code that does not work.

    The GridView control that comes with VB/C# .NET works fine without all this hassle.  I want my money back.

            Protected Sub radGrid2_UpdateCommand( source As Object, e As GridCommandEventArgs ) Handles radGrid2.UpdateCommand  
                    Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)  
                    Dim newValues As New Hashtable()  
                    Dim oldValues As New Hashtable()  
     
                    e.Item.OwnerTableView.ExtractValuesFromItem( newValues, editedItem )  
                    oldValues = TryCast( TryCast( editedItem, GridEditableItem ).SavedOldValues, Hashtable )  
     
                    For Each entry As DictionaryEntry In oldValues  
                            RadAjaxManager1.Alert(( "oldValues Key: " & entry.Key.ToString() & "; oldValues Value: " ) + entry.Value.ToString() )  
                    Next  
     
                    For Each entry As DictionaryEntry In newValues  
                            RadAjaxManager1.Alert( ( "newValues Key: " & entry.Key.ToString() & "; newValues Value: " ) + entry.Value.ToString() )  
                    Next  
                              
            End Sub 

    oldValues prints out the existing values in a row; newValues are the same as the oldValues.  In other words, the text in the edit textboxes is not being captured and Telerik's crap API documentation doesn't work.  Further, the API for modifying the text in edit mode does not work, so when "edit" is clicked, out jumps this big ugly edit text bar full of textboxes with giant fonts.

    Telerik has been giving me BS for 3 days now about this.  Also, if you look at Telerik's reference implementation on page 480 of the "RadControls for ASP.NET Ajax User Guide," they don't even use the primary key to update the record in the database call.  It seems to me they obviously outsourced the documentation and reference solutions to some Indian company and now they cannot answer our questions.

    I have been all through the forums looking at "solutions" given by Telerik techs.  It appears only about half work.  The other half simply point the programmer to some obscure documentation where the code is the same that doesn't work in the first place.  Who the hell is running the show at Telerik?

    Mark
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017