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

inline edit of heiarchial grids

2 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 27 Mar 2012, 08:49 PM

I am putting into my heriarchial grids in-line editing but am running into a problem of how to get at the editing of the lower grids.  i have the 1st grid working but how can I get at the sub grid to edit them inline.  How can I have a unique update name, insert or delete fro each level of the grid.  How can I differenitate between these 2 update commands for differetn grids.  the 1st one is for the top level grid and the second one is for the 1st sub-level. 

Protected Sub myRadGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles myRadGrid.ItemCommand
      'All the Inline Update Commands
      If (e.CommandName = RadGrid.UpdateCommandName) Then
          Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
          Dim Id As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("intCategoryId")
          Dim Cat As TextBox = CType(editedItem.FindControl("txtCategory"), TextBox)
          Dim NSN As TextBox = CType(editedItem.FindControl("txtNSN"), TextBox)
          Dim LIN As TextBox = CType(editedItem.FindControl("txtLin"), TextBox)
          sql = "Update Drat_Category set strCategory = '" & sanitizeString(Cat.Text.ToUpper) & "', strNSN = '" & sanitizeString(NSN.Text.ToUpper) & "', strLIN = '" & sanitizeString(LIN.Text.ToUpper) & "' " _
              & "where intCategoryId = " & Id
          insertUpdateDelete(sql)
          myRadGrid.Rebind()
      End If
      If (e.CommandName = RadGrid.UpdateCommandName) Then
          Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
          Dim Id As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("intManufacturerId")
          Dim Man As TextBox = CType(editedItem.FindControl("txtManufacturer"), TextBox)
          sql = "Update Drat_Manufacturer set strmanufacturer = '" & sanitizeString(Man.Text.ToUpper) & "' where intManufacturerId = " & Id
          insertUpdateDelete(sql)
          myRadGrid.Rebind()

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Mar 2012, 05:37 AM
Hi Kevin,

You can differentiate the UpdateCommandName for each level of Grid by giving Name property and checking for one more condition in ItemCommand event.

Aspx:
<MasterTableView  Name="Master" >
   <DetailTables>
         <telerik:GridTableView   Name="Detail">
           . . .

VB:
Protected Sub RadGrid1_ItemCommand(source As Object, e As GridCommandEventArgs)
             
    If e.CommandName = RadGrid.UpdateCommandName AndAlso e.Item.OwnerTableView.Name = "Master" Then
              'your code    
    End If
          
    If e.CommandName = RadGrid.UpdateCommandName AndAlso e.Item.OwnerTableView.Name = "Detail" Then
              'your code   
    End If
End Sub

Hope this Helps.

Thanks,
Shinu.
0
Kevin
Top achievements
Rank 1
answered on 28 Mar 2012, 01:24 PM
hi,

I tried using that in the line above my original code and got an error on it, but when I put inline as you suggested it works fine.  I also found this method as well, which is basically the same thin but reversed to get it to work, however I like the inline method better.  thanks for the help.

If "MasterGrid".Equals(e.Item.OwnerTableView.Name) Then
           If (e.CommandName = RadGrid.PerformInsertCommandName) Then
               Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
               Dim Cat As TextBox = CType(editedItem.FindControl("txtCategory"), TextBox)
               Dim NSN As TextBox = CType(editedItem.FindControl("txtNSN"), TextBox)
               Dim LIN As TextBox = CType(editedItem.FindControl("txtLin"), TextBox)
               sql = "Insert Drat_Category (strCategory,strNSN, strLIN) VALUES ('" & sanitizeString(Cat.Text.ToUpper) & "', '" & sanitizeString(NSN.Text.ToUpper) & "', " _
                   & "'" & sanitizeString(LIN.Text.ToUpper) & "')"
               insertUpdateDelete(sql)
           End If
       End If
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or