Let me explain.
I have a grid which is made like that:
| <td valign=bottom> |
| <telerik:RadGrid |
| ID="RadGrid2" |
| Skin="Vista" |
| runat="server" |
| OnNeedDataSource="RadGrid2_NeedDataSource" |
| ShowFooter=true |
| CommandItemStyle-HorizontalAlign=Center> |
| <MasterTableView |
| ShowFooter=true |
| CommandItemDisplay="bottom" |
| EditMode="InPlace" > |
| <CommandItemTemplate> |
| <asp:LinkButton ID="LinkButton1" CommandName="UpdateChanges" Runat="server" CssClass="TexteBlanc16">Importer tous</asp:LinkButton> |
| </CommandItemTemplate> |
| <Columns> |
| <telerik:GridTemplateColumn UniqueName="CodePermanent" HeaderText="Code Permanent"> |
| <ItemTemplate> |
| <asp:TextBox ID="TxtCodePermanent" runat="server"></asp:TextBox> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </td> |
| <td valign=bottom> |
| <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Ajouter une ligne" /> |
| </td> |
| Public Sub RadGrid2_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) |
| If Not IsPostBack Then |
| dt = AddRow(dt) |
| ' call the method to create row |
| ViewState("dt") = dt |
| End If |
| dt = DirectCast(ViewState("dt"), DataTable) |
| RadGrid2.DataSource = dt |
| End Sub |
| Private Function AddRow(ByVal dt As DataTable) As DataTable |
| ' method to create row |
| Dim dr As DataRow = dt.NewRow() |
| dr("RowNumber") = "" |
| dt.Rows.Add(dr) |
| Return dt |
| End Function |
| Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) |
| Dim countitem As Integer |
| Dim dt As DataTable = DirectCast(ViewState("dt"), DataTable) |
| countitem = RadGrid2.Items.Count |
| Dim cpt As Integer = 0 |
| For Each Item As GridDataItem In RadGrid2.Items |
| Dim txtcode As TextBox = DirectCast(Item("CodePermanent").FindControl("TxtCodePermanent"), TextBox) |
| If Not (txtcode.Text Is Nothing) And txtcode.Text <> "" Then |
| liste.Add(txtcode.Text) |
| End If |
| Next |
| ViewState("dt") = AddRow(dt) |
| listcount = liste.Count |
| RadGrid2.Rebind() |
| While cpt < listcount |
| Dim txtcode As TextBox = DirectCast(RadGrid2.Items(cpt)("CodePermanent").FindControl("TxtCodePermanent"), TextBox) |
| txtcode.Text = liste.Item(cpt) |
| cptcpt = cpt + 1 |
| End While |
| End Sub |
| Public Sub RadGrid2_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid2.ItemCommand |
| If e.CommandName = "UpdateChanges" Then |
| For Each Item As GridDataItem In RadGrid2.Items |
| Dim txtcode As TextBox = DirectCast(Item("CodePermanent").FindControl("TxtCodePermanent"), TextBox) |
| If Not (txtcode.Text Is Nothing) Then |
| ImporterEtudiants(txtcode.Text) |
| End If |
| Next |
| Me.RadGrid_BanqueCV.Rebind() |
| If CodePermInvalide <> "" Then |
| Session("sCodePermInvalide") = CodePermInvalide |
| Response.Redirect("FEN_ERREUR.aspx?NoErreur=3") |
| End If |
| End If |
| End Sub |
| Public Function ImporterEtudiants(ByVal sCodePerm As String) As Boolean |
| Dim strSQLIdent As String |
| Dim cmdIdent As New SqlCommand |
| Dim myDAIdent As New SqlDataAdapter |
| Dim dsIdent As New DataSet |
| Dim strSQLIdentValide As String |
| Dim cmdIdentValide As New SqlCommand |
| Dim myDAIdentValide As New SqlDataAdapter |
| Dim dsIdentValide As New DataSet |
| Dim strSQLIdentInsert As String |
| Dim cmdIdentInsert As New SqlCommand |
| Dim myDAIdentInsert As New SqlDataAdapter |
| Dim dsIdentInsert As New DataSet |
| Dim DatedeNaissance As Date |
| strSQLIdentValide = "SELECT * FROM T_USAGER WHERE CODE_PERMANENT ='" & sCodePerm & "'" |
| cmdIdentValide = New SqlCommand(strSQLIdentValide, Conn) |
| myDAIdentValide = New SqlDataAdapter(cmdIdentValide) |
| Conn.Open() |
| myDAIdentValide.Fill(dsIdentValide) |
| Conn.Close() |
| If dsIdentValide.Tables(0).Rows.Count > 0 Then 'L'usager existe déjà dans la table T_USAGER |
| Effacer = 1 |
| Return True |
| Else |
| strSQLIdent = "SELECT E_Ele.Fiche,CodePerm,DateNaiss,Nom,Pnom,NoCiv,Rue,Ville,CodePost,IndReg,Tel " & _ |
| "FROM E_Ele " & _ |
| "INNER JOIN E_Adr " & _ |
| "ON E_Ele.Fiche = E_Adr.Fiche " & _ |
| "INNER JOIN E_Freq ON E_Ele.Fiche = E_Freq.Fiche " & _ |
| "GROUP BY E_Ele.Fiche, E_Ele.CodePerm, E_Ele.DateNaiss, E_Ele.Nom, E_Ele.Pnom, E_Adr.NoCiv, E_Adr.Rue, E_Adr.Ville, E_Adr.CodePost, E_Adr.IndReg, E_Adr.Tel, E_Adr.DateFin, E_Adr.EnvoiMeq " & _ |
| "HAVING (((Max(E_Freq.DateFin))>'2008-01-01') AND ((E_Adr.DateFin)='') AND ((E_Adr.EnvoiMeq)='1')) AND CodePerm='" & sCodePerm & "'" |
| cmdIdent = New SqlCommand(strSQLIdent, ConnJadeAdulte) |
| myDAIdent = New SqlDataAdapter(cmdIdent) |
| ConnJadeAdulte.Open() |
| myDAIdent.Fill(dsIdent) |
| ConnJadeAdulte.Close() |
| If dsIdent.Tables(0).Rows.Count > 0 Then |
| DatedeNaissance = Left(dsIdent.Tables(0).Rows(0).Item("DateNaiss"), 4) & "-" & Mid(dsIdent.Tables(0).Rows(0).Item("DateNaiss"), 5, 2) & "-" & Right(dsIdent.Tables(0).Rows(0).Item("DateNaiss"), 2) |
| strSQLIdentInsert = "INSERT INTO T_USAGER (CODE_PERMANENT,MOT_PASSE,PRENOM,NOM,ADRESSE,VILLE,CODE_POSTAL,NO_TEL,COURRIEL,DATE_NAISSANCE,LETTRE_CONSENTEMENT,RECEVOIR_NOUVELLE_OFFRE,DIPLOME, PREMIERE_FOIS) " & _ |
| "VALUES ('" & sCodePerm & "'," & dsIdent.Tables(0).Rows(0).Item("DateNaiss") & ",'" & Replace(Trim(dsIdent.Tables(0).Rows(0).Item("Pnom")), ",", "''") & "', '" & Replace(Trim(dsIdent.Tables(0).Rows(0).Item("Nom")), "'", "''") & "','" & Replace(Trim(dsIdent.Tables(0).Rows(0).Item("NoCiv")), "'", "''") & " " & Replace(Trim(dsIdent.Tables(0).Rows(0).Item("Rue")), "'", "''") & "','" & Replace(Trim(dsIdent.Tables(0).Rows(0).Item("Ville")), "'", "''") & "','" & dsIdent.Tables(0).Rows(0).Item("CodePost") & "','" & dsIdent.Tables(0).Rows(0).Item("IndReg") & dsIdent.Tables(0).Rows(0).Item("Tel") & "','','" & DatedeNaissance & "',0,0,0,1)" |
| cmdIdentInsert = New SqlCommand(strSQLIdentInsert, Conn) |
| myDAIdentInsert = New SqlDataAdapter(cmdIdentInsert) |
| Conn.Open() |
| myDAIdentInsert.Fill(dsIdentInsert) |
| Conn.Close() |
| Effacer = 1 |
| Return True |
| Else |
| If CodePermInvalide = "" Then |
| CodePermInvalide = sCodePerm |
| Else |
| CodePermInvalideCodePermInvalide = CodePermInvalide & " <br> " & sCodePerm |
| End If |
| Effacer = 0 |
| Return False |
| End If |
| End If |
| End Function |
| Private Sub RadGrid2_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid2.PreRender |
| RadGrid2.MasterTableView.RenderColumns(1).Display = False |
| RadGrid2.MasterTableView.RenderColumns(3).Display = False |
| End Sub |
| <A HREF="Javascript:history.go(-1)" >Retour</a> |
Hope that make sense. If you need more informations, please be free to ask as I don't know if I'm clear enought.
Thank you!