how to get radgrid cell data in InsertCommand

7 posts, 0 answers
  1. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 20 Nov 2010 Link to this post

    I diamically added 2 columns to the grid when page load,  one GridHTMLEditorColumn is editable and another one is enabled=false, how I get both Radedit value (edited value and enabled=false's cell value) on InsertCommand and UpdateCommand?

     

     

    On form load:

     

     

     

     

    GridHTMLEditorColumn boundColumn = new GridHTMLEditorColumn();

     

     

     

    // GridBoundColumn boundColumn = new GridBoundColumn(); 

     

     this.rgLanguages.MasterTableView.Columns.Add(boundColumn);

     

     

     

    // this.rgLanguages.MasterTableView.Columns.Add(cBox.Text);

     

     

     

     

     

      

    boundColumn.DataField = cBox.Text;

    boundColumn.HeaderText = cBox.Text;

    boundColumn.UniqueName = cBox.Value;

    rgLanguages_InsertCommand;:

    I tried (editedItem["English"].Controls[0] as RadEditor).Text to get value, it only works for NONE dinamically creaded value, but not work for dinamically created column.

    How I get both editeable value and enbaled =false's Radedit value here?Thank,
    Jessie

     

     

     

     

     

     

     

     

     

    :

     

     

     

     

     

     

  2. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 25 Nov 2010 Link to this post

    Hello Jessie,

    You can extract values from the grid in this way:
    if(e.Item is GridEditableItem)
    {
        GridEditableItem gridEditedItem = e.Item as GridEditableItem;
        TableCell cell = editedItem["ColumnUniqueName"];
        string itemValue = (cell.Controls[0] as TextBox).Text;
    }

    You can use similar logic in the ItemCommand (ItemDatabound) events when the grid is in forms edit mode. More information may be found in the following help article.
    You can also extract  the values from the edit form using the ExtractValuesFromItem method of the GridTableView:
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
            if (e.CommandName == RadGrid.UpdateCommandName)
           {
                if (e.Item is GridEditableItem)
               {
                   GridEditableItem editedItem = e.Item as GridEditableItem;
                   //here editedItem.SavedOldValues will be the dictionary which holds the
                   //predefined values
      
                  //Prepare new dictionary object
                   Hashtable newValues = new Hashtable();
                   e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                  //the newValues instance is the new collection of key -> value pairs
                  //with the updated ny the user data
      
               }
           }
    }
    You can find more information on this approach in this help article.

    Currently the grid have limitation on adding GridHTMLEditorColumn programmatically on Page_Load event but this will be fixed in the next internal build.

    Let me know if you have any other questions.

    Regards,
    Marin
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 02 Feb 2011 Link to this post

    Hi, Marin.  We are using the code you suggested below:
    if(e.Item is GridEditableItem)
    {
        GridEditableItem gridEditedItem = e.Item as GridEditableItem;
        TableCell cell = editedItem["ColumnUniqueName"];
        string itemValue = (cell.Controls[0] as TextBox).Text;
    }

    However, some of our textbox controls are returning with the following error: "Specified argument was out of the range of valid values."

    When I put a break on this line: "string itemValue = (cell.Controls[0] as TextBox).Text", and try to see the control count for this cell, I get 0. 

    However, we can see the textbox for the column on the screen, we can change the value in this textbox, but we cannot access it using this code.

    We have three columns that have this issue.  Their names are "UserID", "Disabled", and "Email"

    Any help would be greatly appreciated.

    Thanks.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2011 Link to this post

    Hello GP,

    If you are using EditMode="EditForms/PopUp", try the following code snippet.
    C#:
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
           {
               GridEditFormItem gridEditedItem = e.Item as GridEditFormItem;
               TableCell cell = gridEditedItem["ColumnUniqueName"];
               string itemValue = (cell.Controls[0] as TextBox).Text;
           }

    And if you are using InPlace EditMode, try the following:

    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem gridEditedItem = e.Item as GridEditableItem;
               TableCell cell = gridEditedItem["ColumnUniqueName"];
               string itemValue = (cell.Controls[0] as TextBox).Text;
           }

    Hope this helps,
    Princy.
  6. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 03 Feb 2011 Link to this post

    Hello GP,

    Indeed the actual code snippet depends on the EditMode you are using. Follow Princy's examples and see if they help. Also additional information on accessing cells and rows can be found in this help article.

    Best wishes,
    Marin
    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.
  7. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 03 Feb 2011 Link to this post

    Princy and Marin,
    Thank you for the help, but we get the same error either way.  I am posting some of my code below.  Does anything look out of place?
    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" AutoGenerateDeleteColumn="True"
        AutoGenerateEditColumn="True" GridLines="None">
        <MasterTableView DataKeyNames="ID" EditMode="EditForms">
        </MasterTableView>
    </telerik:RadGrid>

    VB:
    If (TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode) Then
               Dim gridediteditem As GridEditFormItem = CType(e.Item, GridEditFormItem)
     
               Dim cell As TableCell
               ' This works
               cell = gridediteditem("id")
               Dim id As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("UserID")
               Dim UserID As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("RealName")
               Dim RealName As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("secflag")
               Dim secflag As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("lastdate")
               Dim lastdate As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("Disabled")
               Dim Disabled As String = CType(cell.Controls(0), TextBox).Text
               cell = gridediteditem("Email")
               Dim Email As String = CType(cell.Controls(0), TextBox).Text
           End If

    Also, I just used a hashtable, and the data from userid pulls in, but I'm still trying to figure out how to get all this information out using this method.  I had hoped that using the above method would work, but it doesn't seem to.
  8. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 03 Feb 2011 Link to this post

    Never mind.  I got the hashtable to work.  I used the following, and it works pretty well. Here's what I ended up using:

    If (TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode) Then
                Dim gridediteditem As GridEditFormItem = CType(e.Item, GridEditFormItem)
     
                Dim newValues As Hashtable = New Hashtable
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, gridediteditem)
     
                Dim id As String
                If newValues.Item("id") = Nothing Then
                    id = ""
                Else
                    id = newValues.Item("id").ToString()
                End If
     
                Dim UserID As String
                If newValues.Item("UserId") = Nothing Then
                    UserID = ""
                Else
                    UserID = newValues.Item("UserId").ToString()
                End If
     
                Dim RealName As String
                If newValues.Item("RealName") = Nothing Then
                    RealName = ""
                Else
                    RealName = newValues.Item("RealName").ToString()
                End If
     
                Dim secflag As String
                If newValues.Item("secflag") = Nothing Then
                    secflag = ""
                Else
                    secflag = newValues.Item("secflag").ToString()
                End If
     
                Dim lastdate As String
                If newValues.Item("lastdate") = Nothing Then
                    lastdate = ""
                Else
                    lastdate = newValues.Item("lastdate").ToString()
                End If
     
                Dim Disabled As String
                If newValues.Item("disabled") = Nothing Then
                    Disabled = ""
                Else
                    Disabled = newValues.Item("disabled").ToString()
                End If
     
                Dim Email As String = newValues.Item("email").ToString()
                If newValues.Item("email") = Nothing Then
                    Email = ""
                Else
                    Email = newValues.Item("email").ToString()
                End If
     
                MsgBox("Changing" & id & "/" & UserID & "/" & RealName & "/" & secflag & "/" & Disabled & "/" & Email & "/" & lastdate)
     
                'MsgBox(id & "/" & UserID & "/" & RealName & "/" & secflag & "/" & Disabled & "/" & Email)
            End If


    Thanks for your help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017