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

RadGrid_ItemCommand get a column's value when I know only the first 3 characters of the column name

2 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Myriam
Top achievements
Rank 1
Myriam asked on 25 May 2009, 01:46 PM
Hello
I have a radgrid which is build from a cross table.
I need the get column's value, from the Radgrid_ItemCommand. The thing is that I don't know the whole name of the column. I only know the first 3 characters ("TRA") of the column.
Here is my code
Private Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
        If e.CommandName = "UpdateAll" Then 
            For Each editedItem As GridEditableItem In RadGrid1.EditItems  
                Dim newValues As New Hashtable()  
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)  
                SqlDsIntervenant.InsertCommand = String.Format("INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & newValues("FICHE") & ",'" & newValues("MAT") & "', '" & newValues("GRP") & "', '" & newValues("NO_INTERV") & "', '" & newValues("COMPTENCES") & "','" & newValues("NOM") & "','" & newValues("PNOM") & "')")  
                SqlDsIntervenant.Insert()  
 
                editedItem.Edit = False 
            Next 
        End If 
        RadGrid1.Rebind()  
    End Sub 
Does somebody know how to get that?
Thank you!

2 Answers, 1 is accepted

Sort by
0
Myriam
Top achievements
Rank 1
answered on 25 May 2009, 08:26 PM
I tried this but the "competence" field always gives me " " in my table. And I would like to have the whole name of the column which begin by "TRA" if possible. That's what I was trying to do with this line without succeed



  'Matiere = CType(editedItem, GridDataItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(cpt), GridBoundColumn).UniqueName)   
Imports
 System.Data.SqlClient  
Imports System.Data  
Imports System.Data.OleDb  
Imports System  
Imports Telerik.Web.UI  
Imports System.Configuration  
 
Partial Public Class FEN_COMPETENCES_TRANSVERSALES_FINALES  
    Inherits System.Web.UI.Page  
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then 
            Dim dsLogin As New DataSet  
            dsLogin = Session("sDsLogin")  
            Me.SqlDsIntervenant.SelectParameters("ID_ECO").DefaultValue = dsLogin.Tables(0).Rows(0).Item("ID_ECO")  
            Me.SqlDsIntervenant.SelectParameters("NO_INTERV").DefaultValue = dsLogin.Tables(0).Rows(0).Item("NO_INTERV")  
            Me.SqlDsIntervenant.SelectParameters("ANNEE").DefaultValue = Session("sAnnee")  
            
 
            Me.SqlDsLegende.SelectParameters("ID_ECO").DefaultValue = dsLogin.Tables(0).Rows(0).Item("ID_ECO")  
            Me.SqlDSLegende.SelectParameters("INTERV").DefaultValue = dsLogin.Tables(0).Rows(0).Item("NO_INTERV")  
 
 
        End If 
          
    End Sub 
 
    Private Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If (e.Column.ColumnType = "GridBoundColumn"AndAlso (Left(e.Column.UniqueName, 3) <> "TRA"AndAlso e.Column.UniqueName <> "NOM" AndAlso e.Column.UniqueName <> "PNOM" AndAlso e.Column.UniqueName <> "FICHE" AndAlso e.Column.UniqueName <> "ID_ECO" AndAlso e.Column.UniqueName <> "ANNEE" AndAlso e.Column.UniqueName <> "NO_INTERV" AndAlso e.Column.UniqueName <> "GRP" Then 
            Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            bndcol.[ReadOnly] = True 
 
        End If 
 
    End Sub 
 
     
 
    Private Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
        If e.CommandName = "UpdateAll" Then 
            For Each editedItem As GridEditableItem In RadGrid1.EditItems  
                Dim newValues As New Hashtable()  
                Dim Competence As String 
                Dim Matiere As String 
                Dim cpt As Integer = 0  
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)  
 
                While cpt < editedItem.Controls.Count - 2  
                    If Left(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(cpt), GridBoundColumn).UniqueName, 3) = "TRA" Then 
                        Competence = CType(editedItem, GridEditableItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(cpt), GridBoundColumn).UniqueName).Text  
                        'Matiere = CType(editedItem, GridDataItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(cpt), GridBoundColumn).UniqueName)  
                        Exit While 
                    End If 
                    cpt = cpt + 1  
                End While 
                'If Left(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(0), GridBoundColumn).UniqueName, 3) = "TRA" Then  
                'If TypeOf e.Item Is GridDataItem Then  
                'Competence = CType(editedItem, GridDataItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(0), GridBoundColumn).UniqueName).Text  
                ' CType(e.Item, GridDataItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(0), GridBoundColumn).UniqueName).BackColor = System.Drawing.SystemColors.Control  
                ' CType(e.Item, GridDataItem)(CType(RadGrid1.MasterTableView.AutoGeneratedColumns(0), GridBoundColumn).UniqueName).BorderColor = System.Drawing.Color.White  
                'End If  
 
 
 
                SqlDsIntervenant.InsertCommand = String.Format("INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & newValues("FICHE") & ",'" & Matiere & "', '" & newValues("GRP") & "', '" & newValues("NO_INTERV") & "', '" & Competence & "','" & newValues("NOM") & "','" & newValues("PNOM") & "')")  
                SqlDsIntervenant.Insert()  
 
                editedItem.Edit = False 
                '  End If  
            Next 
        End If 
        RadGrid1.Rebind()  
    End Sub 
 
 
    Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
         
        e.Item.OwnerTableView.GetColumn("ID_ECO").Display = False 
        e.Item.OwnerTableView.GetColumn("NO_INTERV").Display = False 
        e.Item.OwnerTableView.GetColumn("ANNEE").Display = False 
        e.Item.OwnerTableView.GetColumn("NOM").Display = False 
        e.Item.OwnerTableView.GetColumn("PNOM").Display = False 
        e.Item.OwnerTableView.GetColumn("FICHE").Display = False 
        e.Item.OwnerTableView.GetColumn("GRP").Display = False 
    End Sub 
 
 
    Public Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
        
        For Each item As GridDataItem In RadGrid1.MasterTableView.Items  
            item.Edit = True 
              
        Next 
        RadGrid1.MasterTableView.Rebind()  
 
        For Each edititem As GridEditableItem In RadGrid1.MasterTableView.GetItems(GridItemType.EditItem)  
            For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns  
                If col.ColumnType = "GridBoundColumn" Then 
                    If edititem.IsInEditMode Then 
                        Dim txtbx As TextBox = DirectCast(edititem(col.UniqueName).Controls(0), TextBox)  
                        txtbx.Width = 50  
                        If txtbx.Text = "NE" Then 
                            txtbx.Text = "" 
                        End If 
                    End If 
                End If 
                
            Next 
        Next 
 
    End Sub 
 
 
End Class 
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="FEN_COMPETENCES_TRANSVERSALES_FINALES.aspx.vb" Inherits="Competences_Transversales_Web.FEN_COMPETENCES_TRANSVERSALES_FINALES" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
      <title>Comp├ętences transversales WEB</title> 
          <link href="StyleSheet1.css" type="text/css" rel="stylesheet"/>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
     
            <asp:SqlDataSource ID="SqlDsIntervenant" runat="server"   
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"   
            selectcommand="TRANSFORM Min(IIf(IsNull([COMPTENCES]),'NE',[comptences])) AS MinDeCOMPTENCES SELECT Req_Tuteur_de_Quel_Eleve.NOM & ', ' & Req_Tuteur_de_Quel_Eleve.PNOM as Eleve , Req_Tuteur_de_Quel_Eleve.ID_ECO, Req_Tuteur_de_Quel_Eleve.ANNEE, Req_Tuteur_de_Quel_Eleve.NOM, Req_Tuteur_de_Quel_Eleve.PNOM, Req_Tuteur_de_Quel_Eleve.FICHE, Req_Tuteur_de_Quel_Eleve.NO_INTERV,Req_Tuteur_de_Quel_Eleve.GRP FROM ((Req_Tuteur_de_Quel_Eleve INNER JOIN dbo_GPM_E_MAT_ELE ON Req_Tuteur_de_Quel_Eleve.FICHE = dbo_GPM_E_MAT_ELE.FICHE AND Req_Tuteur_de_Quel_Eleve.ID_ECO = dbo_GPM_E_MAT_ELE.ID_ECO) LEFT JOIN T_COMPTENCES_TRANVERSALES ON dbo_GPM_E_MAT_ELE.GRP = T_COMPTENCES_TRANVERSALES.GRP AND dbo_GPM_E_MAT_ELE.MAT = T_COMPTENCES_TRANVERSALES.MAT AND dbo_GPM_E_MAT_ELE.FICHE = T_COMPTENCES_TRANVERSALES.FICHE) INNER JOIN dbo_GPM_T_MAT ON dbo_GPM_E_MAT_ELE.MAT = dbo_GPM_T_MAT.MAT AND dbo_GPM_E_MAT_ELE.ID_ECO = dbo_GPM_T_MAT.ID_ECO WHERE ((Req_Tuteur_de_Quel_Eleve.ID_ECO=?)  AND (Req_Tuteur_de_Quel_Eleve.NO_INTERV=?) AND (Req_Tuteur_de_Quel_Eleve.ANNEE=?)) GROUP BY Req_Tuteur_de_Quel_Eleve.NOM & ', ' & Req_Tuteur_de_Quel_Eleve.PNOM , Req_Tuteur_de_Quel_Eleve.ID_ECO, Req_Tuteur_de_Quel_Eleve.ANNEE,Req_Tuteur_de_Quel_Eleve.NOM, Req_Tuteur_de_Quel_Eleve.PNOM, Req_Tuteur_de_Quel_Eleve.FICHE, Req_Tuteur_de_Quel_Eleve.NO_INTERV, Req_Tuteur_de_Quel_Eleve.ECO, Req_Tuteur_de_Quel_Eleve.GRP PIVOT dbo_GPM_T_MAT.mat & '-' & Left([DESCR],6)">  
            <SelectParameters> 
                <asp:Parameter Name="ID_ECO" Type="int32" /> 
                <asp:Parameter Name="NO_INTERV" Type="String" /> 
                <asp:Parameter Name="ANNEE" Type="int32" /> 
            </SelectParameters> 
              
        </asp:SqlDataSource> 
          
          
          
        <asp:SqlDataSource id="SqlDSLegende" runat="server" 
            connectionstring="<%$ ConnectionStrings:ConnectionString %>" 
            providerName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
            selectcommand="SELECT R_MSG_CODE.CODE_MSG_CODE,R_MSG_CODE.DESCR FROM R_MSG_CODE WHERE (((R_MSG_CODE.INTERV)=?) AND ((R_MSG_CODE.ID_ECO)=?)) ORDER BY CODE_MSG_CODE">  
            <SelectParameters> 
                <asp:Parameter Name="INTERV" Type="String" /> 
                <asp:Parameter Name="ID_ECO" Type="int32" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 
 
     <asp:ScriptManager ID="ScriptManager1" runat=server></asp:ScriptManager> 
     <table width="100%">  
            <tr> 
                <td colspan=2 align=center><asp:Label ID="Label1" runat="server" Font-size=X-Large Text="Commission Scolaire de la BEAUCE-ETCHEMIN"></asp:Label></td>  
            </tr> 
            <tr> 
                <td height="20px" align=right valign=top><asp:Label ID="Label2" runat="server" Font-Size=Smaller Text="Ensemble"></asp:Label>&nbsp;</td> 
                <td align=left valign=bottom><asp:Label ID="Label3" runat="server" Font-Size=Smaller Font-Italic=true Text="vers l'avenir"></asp:Label></td>  
            </tr> 
            <tr> 
                <td colspan=2 align=center><asp:Label ID="Label4" runat="server" Font-Size=Larger Text="Comp├ętences transversales"></asp:Label></td>  
            </tr> 
            <tr> 
                <td colspan=2 align=center>  
                    <telerik:RadGrid   
                        ID="RadGrid2"   
                        runat="server"   
                        GridLines="Both"   
                        Skin="Web20" 
                        width="80%" 
                        DataSourceID="SqlDslegende">  
                          
                        <MasterTableView   
                           datasourceid="SqlDSlegende"   
                           Name="MTVLegende" 
                           AutoGenerateColumns=false 
                           CssClass="Legende" 
                           NoMasterRecordsText="Aucun enregistrement"   
                           NoDetailRecordsText="Aucun enregistrement" 
                           ItemStyle-Font-Size=X-Small   
                            ItemStyle-Wrap=true 
                           AlternatingItemStyle-Font-Size=X-Small> 
                             
                            <ItemStyle CssClass="Row1" />    
                                <AlternatingItemStyle CssClass="Row1" />    
                                <FooterStyle CssClass="Row1" /> 
                                  
                           <Columns> 
                                  
                                <telerik:GridBoundColumn  
                                    DataField="CODE_MSG_CODE"   
                                    UniqueName="CODE_MSG_CODE" 
                                    HeaderText="Code" 
                                    ReadOnly=true>  
                                </telerik:GridBoundColumn> 
                                  
                                <telerik:GridBoundColumn  
                                    DataField="DESCR"   
                                    UniqueName="DESCR" 
                                    HeaderText="Description" 
                                    ReadOnly=true ItemStyle-HorizontalAlign=Left>  
                                </telerik:GridBoundColumn> 
                            </Columns> 
                        </MasterTableView> 
                    </telerik:RadGrid> 
                </td> 
            </tr> 
     </table> 
       
       
        <br /> 
         <telerik:RadGrid   
            ID="RadGrid1"   
            runat="server"   
            GridLines="Both"   
            AllowAutomaticUpdates=true 
            AllowMultiRowEdit = "True" 
            Skin="Web20" 
            DataSourceID="SqlDsIntervenant"   
            OnPreRender="RadGrid1_PreRender" 
            > 
              
            <MasterTableView   
               datasourceid="SqlDSIntervenant"   
                Name="MTVIntervenant" 
                HierarchyDefaultExpanded=true   
                AllowAutomaticUpdates=true 
                ExpandCollapseColumn-HeaderStyle-Width="5px" 
                ExpandCollapseColumn-HeaderStyle-HorizontalAlign="Left"   
                AutoGenerateColumns=true 
                EditMode="InPlace" 
                CommandItemDisplay="TopAndBottom" 
                NoMasterRecordsText="Aucun enregistrement"   
                NoDetailRecordsText="Aucun enregistrement" 
                > 
                  
                   <Columns> 
                     
                        
                         
                   </Columns> 
                   <CommandItemTemplate> 
                       <asp:Button runat="server" ID="UpdateAll" Text="Update All" CommandName="UpdateAll" /> 
                        
                   </CommandItemTemplate> 
                      
            </MasterTableView> 
        </telerik:RadGrid> 
        <br /> 
        <table width="100%">  
            <tr> 
                <td align=center>  
                    <telerik:RadGrid   
                        ID="RadGrid3"   
                        runat="server"   
                        GridLines="Both"   
                        Skin="Web20" 
                        width="80%" 
                        DataSourceID="SqlDslegende">  
                          
                        <MasterTableView   
                           datasourceid="SqlDSlegende"   
                           Name="MTVLegende" 
                           AutoGenerateColumns=false 
                           CssClass="Legende" 
                           NoMasterRecordsText="Aucun enregistrement"   
                           NoDetailRecordsText="Aucun enregistrement" 
                           ItemStyle-Font-Size=X-Small   
                            ItemStyle-Wrap=true 
                           AlternatingItemStyle-Font-Size=X-Small> 
                             
                            <ItemStyle CssClass="Row1" />    
                                <AlternatingItemStyle CssClass="Row1" />    
                                <FooterStyle CssClass="Row1" /> 
                                  
                           <Columns> 
                                  
                                <telerik:GridBoundColumn  
                                    DataField="CODE_MSG_CODE"   
                                    UniqueName="CODE_MSG_CODE" 
                                    HeaderText="Code" 
                                    ReadOnly=true>  
                                </telerik:GridBoundColumn> 
                                  
                                <telerik:GridBoundColumn  
                                    DataField="DESCR"   
                                    UniqueName="DESCR" 
                                    HeaderText="Description" 
                                    ReadOnly=true ItemStyle-HorizontalAlign=Left>  
                                </telerik:GridBoundColumn> 
                            </Columns> 
                        </MasterTableView> 
                    </telerik:RadGrid> 
                </td> 
            </tr> 
        </table> 
    </div> 
    </form> 
</body> 
</html> 
 

Thank you very much!
0
Myriam
Top achievements
Rank 1
answered on 26 May 2009, 12:56 PM
Here is what I did if it can help someone else

  Private Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
 
        If (e.Column.ColumnType = "GridBoundColumn"AndAlso (Left(e.Column.UniqueName, 3) <> "TRA"AndAlso e.Column.UniqueName <> "NOM" AndAlso e.Column.UniqueName <> "PNOM" AndAlso e.Column.UniqueName <> "FICHE" AndAlso e.Column.UniqueName <> "ID_ECO" AndAlso e.Column.UniqueName <> "ANNEE" AndAlso e.Column.UniqueName <> "NO_INTERV" AndAlso e.Column.UniqueName <> "GRP" Then 
            Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            bndcol.[ReadOnly] = True 
        ElseIf (Left(e.Column.UniqueName, 3) = "TRA"Then 
            Session("sTempCompUniqueId") = e.Column.UniqueName  
        End If 
 
    End Sub 
 
     
 
    Private Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
        If e.CommandName = "UpdateAll" Then 
            For Each editedItem As GridEditableItem In RadGrid1.EditItems  
                Dim newValues As New Hashtable()  
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)  
                SqlDsIntervenant.InsertCommand = String.Format("INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & newValues("FICHE") & ",'" & Session("sTempCompUniqueId") & "', '" & newValues("GRP") & "', '" & newValues("NO_INTERV") & "', '" & newValues(Session("sTempCompUniqueId")) & "','" & newValues("NOM") & "','" & newValues("PNOM") & "')")  
                SqlDsIntervenant.Insert()  
 
                editedItem.Edit = False 
 
            Next 
        End If 
        RadGrid1.Rebind()  
    End Sub 
YEAH!!
Tags
Grid
Asked by
Myriam
Top achievements
Rank 1
Answers by
Myriam
Top achievements
Rank 1
Share this question
or