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

Get the edit value from custom "save" button

4 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Myriam
Top achievements
Rank 1
Myriam asked on 13 May 2009, 03:04 PM
Hello
I have a radgrid with some column but only one editable column. When the radgrid is load, I put it automatiquly in Edit mode for each rows (with the wonderfull  "allowmultiRowEdit" property). Now I have created a custom button to save all rows at the same time. But guess what?! It doesn't work. I can't get the value on the edit column "Comptence" in the sub of the custom save button.
Here is my code

 Public Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
        
        If Not IsPostBack Then 
            For Each item As GridItem In RadGrid1.MasterTableView.Items  
                If TypeOf item Is GridEditableItem Then 
                    Dim editableItem As GridEditableItem = CType(item, GridDataItem)  
                    editableItem.Edit = True 
                End If 
            Next 
            RadGrid1.Rebind()  
        End If 
 
    End Sub 
 
    Private Sub BntSave_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles BntSave.Click  
         
        Dim StrInsert As String 
        Dim Fiche As Integer 
        Dim Mat As String 
        Dim Grp As Integer 
        Dim Interv As Integer 
        Dim Nom As String 
        Dim Prenom As String 
        Dim Competence As String 
        Dim cmdComp As OleDbCommand  
        Dim myDAComp As OleDbDataAdapter  
        Dim dsComp As New DataSet  
 
          
        For Each item As GridDataItem In RadGrid1.Items  
            Dim editItem As GridEditableItem = DirectCast(item, GridEditableItem)  
            Dim strtxt As String = editItem.Item("COMPTENCES").Text  
 
            If strtxt <> "" Then 
                Fiche = item("FICHE").Text  
                Mat = item("MAT").Text  
                Grp = item("GRP").Text  
                Interv = item("INTERV").Text  
                Nom = item("NOM").Text  
                Prenom = item("PNOM").Text  
                Competence = item("COMPTENCES").Text  
 
                StrInsert = "INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & Fiche & ", '" & Mat & "', '" & Grp & "', '" & Interv & "', '" & Competence & "','" & Nom & "','" & Prenom & "')" 
                cmdComp = New OleDbCommand(StrInsert, Conn)  
                myDAComp = New OleDbDataAdapter(cmdComp)  
                Conn.Open()  
                myDAComp.Fill(dsComp)  
                Conn.Close()  
 
            End If 
        Next 
    End Sub 
   <telerik:RadGrid   
            ID="RadGrid1"   
            runat="server"   
            GridLines="None"   
            AllowAutomaticUpdates=true 
            AllowMultiRowEdit = "True" 
            Skin="Web20" 
            DataSourceID="SqlDsIntervenant"   
            OnPreRender="RadGrid1_PreRender">  
              
            <MasterTableView   
                EditMode="EditForms"   
                datasourceid="SqlDSIntervenant"   
                HierarchyDefaultExpanded=true   
                AllowAutomaticUpdates=true 
                ExpandCollapseColumn-HeaderStyle-Width="5px" 
                ExpandCollapseColumn-HeaderStyle-HorizontalAlign="Left"   
                AutoGenerateColumns=false   
                > 
                  
                   <Columns> 
                     
                        <telerik:GridBoundColumn  
                            DataField="INTERV"   
                            UniqueName="INTERV" 
                            HeaderText="Intervenant" 
                            ReadOnly=true 
                            Visible=false>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="MAT"   
                            UniqueName="MAT" 
                            HeaderText="Matière" 
                            ReadOnly=true>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="DESCR"   
                            UniqueName="DESCR" 
                            HeaderText="Description" 
                            ReadOnly=true>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="GRP"   
                            UniqueName="GRP" 
                            HeaderText="Groupe" 
                            ReadOnly=true>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="FICHE"   
                            UniqueName="FICHE" 
                            HeaderText="Fiche" 
                            ReadOnly=true 
                            Visible=false>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="PNOM"   
                            UniqueName="PNOM" 
                            HeaderText="Prénom Élève" 
                            ReadOnly=true>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="NOM"   
                            UniqueName="NOM" 
                            HeaderText="Nom Élève" 
                            ReadOnly=true>  
                        </telerik:GridBoundColumn> 
                          
                        <telerik:GridBoundColumn  
                            DataField="COMPTENCES"   
                            UniqueName="COMPTENCES" 
                            HeaderText="Compétences" 
                            Visible=false>  
                        </telerik:GridBoundColumn> 
                   </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
        <asp:Button ID="BntSave" runat="server" Text="Sauvegarder" /> 
Can anyone help me to get those values?
Thank you!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 14 May 2009, 10:01 AM
Hello Myriam,

Try out the following code to access the text for the editable column on clicking a button outside the grid:
VB:
Private Sub BntSave_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles BntSave.Click   
          
        Dim StrInsert As String  
        Dim Fiche As Integer  
        Dim Mat As String  
        Dim Grp As Integer  
        Dim Interv As Integer  
        Dim Nom As String  
        Dim Prenom As String  
        Dim Competence As String  
        Dim cmdComp As OleDbCommand   
        Dim myDAComp As OleDbDataAdapter   
        Dim dsComp As New DataSet   
  
           
        For Each item As GridDataItem In RadGrid1.EditItems 
        Dim editedItem As GridEditableItem = DirectCast(item.EditFormItem, GridEditableItem) 
        Dim strtxt As String = DirectCast(editedItem("COMPTENCES").Controls(0), TextBox).Text 
  
            If strtxt <> "" Then  
                Fiche = item("FICHE").Text   
                Mat = item("MAT").Text   
                Grp = item("GRP").Text   
                Interv = item("INTERV").Text   
                Nom = item("NOM").Text   
                Prenom = item("PNOM").Text   
                Competence = item("COMPTENCES").Text   
  
                StrInsert = "INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & Fiche & ", '" & Mat & "', '" & Grp & "', '" & Interv & "', '" & Competence & "','" & Nom & "','" & Prenom & "')"  
                cmdComp = New OleDbCommand(StrInsert, Conn)   
                myDAComp = New OleDbDataAdapter(cmdComp)   
                Conn.Open()   
                myDAComp.Fill(dsComp)   
                Conn.Close()   
  
            End If  
        Next  
End Sub  

Thanks
Princy.
0
Myriam
Top achievements
Rank 1
answered on 14 May 2009, 01:28 PM
Hello Princy
It doesn't seems to like that line:

 

Dim strtxt As String = DirectCast(editedItem("COMPTENCES").Controls(0), TextBox).Text
as it doesn't find the textbox (as it's a bound column and not a template column).
does that make sense?
Thank you
Myriam

 

0
Myriam
Top achievements
Rank 1
answered on 14 May 2009, 01:35 PM
Oh I just saw that editedItem is = to nothing....
0
Myriam
Top achievements
Rank 1
answered on 20 May 2009, 01:23 PM
why the edititem is = to nothing? I didn't find it by myself
Please help...
Tags
Grid
Asked by
Myriam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Myriam
Top achievements
Rank 1
Share this question
or