begin process at 2012 05 27 20:57:02
  Trouver un code source :
 
dans
 
Accueil > Forum > 

ASP.NET

 > 

Web 2.0

 > 

datagrid ves gridview


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

datagrid ves gridview

jeudi 9 août 2007 à 10:24:04 | datagrid ves gridview

garnier54

Membre Club
boujour

j'avais recuperé un prograne VB tres pratique pour moi, qui prenet la gestion total d'un Data Grid  , supression , modification , ajout
j'aimerai l'adapter au gridview mais j' ai du mal a faire la modification.
Ce programme existe sans doute sur le met , pouvez vous me venir en aide ?
voici le programme que j 'aimerai transformé merci

<%

@PageLanguage="VB"Debug="true" %>

<%

@importNamespace="System.Data" %>

<%

@importNamespace="System.Data.SqlClient" %>

<

scriptrunat="server">

Private dsn AS string = ConfigurationSettings.AppSettings("DSN")

' TODO: update the ConnectionString and Command values for your application

Dim ConnectionString As String = dsn

Dim SelectCommand As String = "SELECT si_no, si_adresse, si_cp, si_ville , si_admin from q_site"

Dim isEditing As Boolean = False

dim compteur as integer

Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

If Not Page.IsPostBack Then

BindGrid()

End If

End Sub

' ---------------------------------------------------------------

'

' DataGrid Commands: Page, Sort, Edit, Update, Cancel, Delete

'

Sub DataGrid_ItemCommand(Sender As Object, E As DataGridCommandEventArgs)

CheckIsEditing(e.CommandName)

End Sub

Sub CheckIsEditing(commandName As String)

If DataGrid1.EditItemIndex <> -1 Then

' we are currently editing a row

If commandName <> "Cancel" And commandName <> "Update" Then

' user's edit changes (If any) will not be committed

Message.Text = "effectuer la mise a jour ou la suppression avant !." & commandname

isEditing = True

End If

End If

End Sub

Sub DataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)

' turn on editing for the selected row

If Not isEditing Then

DataGrid1.EditItemIndex = e.Item.ItemIndex

BindGrid()

End If

End Sub

Sub DataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)

' keyvalue = l'index du datagrid de la nem ligne

Dim keyValue As String = CStr(DataGrid1.DataKeys(e.Item.ItemIndex))

id = viewstate("counter")

'message.text=id

Dim adr As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Dim cp As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text

Dim ville As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text

Dim admin As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text

' TODO: update the Command value for your application

Dim myConnection As New SqlConnection(ConnectionString)

Dim UpdateCommand As SqlCommand = new SqlCommand()

UpdateCommand.Connection = myConnection

UpdateCommand.Parameters.Add("@si_adresse", SqlDbType.nVarChar, 30).Value = adr

UpdateCommand.Parameters.Add("@si_cp", SqlDbType.nVarChar, 5).Value = cp

UpdateCommand.Parameters.Add("@si_ville", SqlDbType.nVarChar, 10).Value = ville

UpdateCommand.Parameters.Add("@si_admin", SqlDbType.nVarChar, 10).Value = admin

If AddingNew = True Then

UpdateCommand.CommandText = "INSERT INTO q_site(si_adresse,si_cp,si_ville, si_admin) VALUES (@si_adresse, @si_cp, @si_ville, @si_admin)"

Else

UpdateCommand.CommandText = "UPDATE q_site SET si_adresse = @si_adresse, si_cp= @si_cp, si_ville = @si_ville, si_admin= @si_admin WHERE si_no = '" & keyValue & "'"

End If

' execute the command

Try

myConnection.Open()

UpdateCommand.ExecuteNonQuery()

Catch ex as Exception

Message.Text = ex.ToString()

Finally

myConnection.Close()

End Try

' Resort the grid for new records

If AddingNew = True Then

DataGrid1.CurrentPageIndex = 0

AddingNew = false

End If

' rebind the grid

DataGrid1.EditItemIndex = -1

BindGrid()

End Sub

Sub DataGrid_Cancel(Sender As Object, E As DataGridCommandEventArgs)

' cancel editing

DataGrid1.EditItemIndex = -1

BindGrid()

AddingNew = False

End Sub

Sub DataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs)

' delete the selected row

If Not isEditing Then

' the key value for this row is in the DataKeys collection

Dim keyValue As String = CStr(DataGrid1.DataKeys(e.Item.ItemIndex))

' TODO: update the Command value for your application

Dim myConnection As New SqlConnection(ConnectionString)

Dim DeleteCommand As New SqlCommand("DELETE from q_site where si_no='" & keyValue & "'", myConnection)

'execute the command

Try

myConnection.Open()

DeleteCommand.ExecuteNonQuery()

Catch ex as Exception

Message.Text = keyValue

'Message.Text ="Suppression impossible il existe des machines pour cette Societe !"

Finally

myConnection.Close()

End Try

'myConnection.Open()

'DeleteCommand.ExecuteNonQuery()

'myConnection.Close()

' rebind the grid

DataGrid1.CurrentPageIndex = 0

DataGrid1.EditItemIndex = -1

BindGrid()

End If

End Sub

Sub DataGrid_Page(Sender As Object, E As DataGridPageChangedEventArgs)

' display a new page of data

If Not isEditing Then

DataGrid1.EditItemIndex = -1

DataGrid1.CurrentPageIndex = e.NewPageIndex

BindGrid()

End If

End Sub

Sub AddNew_Click(Sender As Object, E As EventArgs)

' add a new row to the end of the data, and set editing mode 'on'

CheckIsEditing("")

If Not isEditing = True Then

' set the flag so we know to do an insert at Update time

AddingNew = True

' add new row to the end of the dataset after binding

' first get the data

Dim myConnection As New SqlConnection(ConnectionString)

Dim myCommand As New SqlDataAdapter(SelectCommand, myConnection)

Dim ds As New DataSet()

myCommand.Fill(ds)

' add a new blank row to the end of the data

Dim rowValues As Object() = { "0", "","","",""}

ds.Tables(0).Rows.Add(rowValues)

' figure out the EditItemIndex, last record on last page

Dim recordCount As Integer = ds.Tables(0).Rows.Count

If recordCount > 0 Then

recordCount -= 1

DataGrid1.CurrentPageIndex = recordCount \ DataGrid1.PageSize

DataGrid1.EditItemIndex = recordCount Mod DataGrid1.PageSize

End If

' databind

DataGrid1.DataSource = ds

DataGrid1.DataBind()

End If

End Sub

' ---------------------------------------------------------------

'

' Helpers Methods:

'

' property to keep track of whether we are adding a new record,

' and save it in viewstate between postbacks

Property AddingNew() As Boolean

Get

Dim o As Object = ViewState("AddingNew")

If o Is Nothing Then

Return False

End If

Return CBool(o)

End Get

Set(ByVal Value As Boolean)

ViewState("AddingNew") = Value

End Set

End Property

Sub BindGrid()

Dim myConnection As New SqlConnection(ConnectionString)

Dim myCommand As New SqlDataAdapter(SelectCommand, myConnection)

dim ds As New DataSet()

myCommand.Fill(ds)

DataGrid1.DataSource = ds

DataGrid1.DataBind()

End Sub

</

script>

<

html>

<

head>

</

head>

<

bodystyle="FONT-FAMILY: arial"bgcolor="#003399">

<h2>Gestion des usines

</h2>

<hrsize="1"/>

<formrunat="server">

<asp:datagridid="DataGrid1"runat="server"DataKeyField="si_no"OnItemCommand="DataGrid_ItemCommand"OnEditCommand="DataGrid_Edit"OnUpdateCommand="DataGrid_Update"OnCancelCommand="DataGrid_Cancel"OnDeleteCommand="DataGrid_Delete"AllowPaging="true"PageSize="10"OnPageIndexChanged="DataGrid_Page"ForeColor="Black"BackColor="White"CellPadding="3"GridLines="None"CellSpacing="1"width="70%"autogeneratecolumns="false">

<HeaderStylefont-bold="True"forecolor="white"backcolor="#4A3C8C"></HeaderStyle>

<PagerStylehorizontalalign="Right"backcolor="#C6C3C6"mode="NumericPages"font-size="smaller"></PagerStyle>

<ItemStylebackcolor="#DEDFDE"></ItemStyle>

<FooterStylebackcolor="#C6C3C6"></FooterStyle>

<Columns>

<asp:EditCommandColumnButtonType="LinkButton"UpdateText="maj"CancelText="annu"EditText="Edit"ItemStyle-Font-Size="smaller"ItemStyle-Width="10%"></asp:EditCommandColumn>

<asp:ButtonColumnText="sup"CommandName="Delete"ItemStyle-Font-Size="smaller"ItemStyle-Width="10%"></asp:buttoncolumn>

<asp:boundcolumnheadertext=" Lib,ll,"datafield="si_adresse"></asp:boundcolumn>

<asp:boundcolumnheadertext=" cp"datafield="si_cp"></asp:boundcolumn>

<asp:boundcolumnheadertext=" Ville"datafield="si_ville"></asp:boundcolumn>

<asp:boundcolumnheadertext=" admin"datafield="si_admin"></asp:boundcolumn>

</Columns>

</asp:datagrid>

<br/>

<asp:LinkButtonid="LinkButton1"onclick="AddNew_Click"runat="server"ForeColor="White"Text="Ajout"Font-Size="smaller"></asp:LinkButton>

<br/>

<palign="left">

<asp:HyperLinkid="menu"runat="server"ForeColor="White"Font-Size="Smaller"NavigateUrl="qualite.aspx">Menu</asp:HyperLink>

</p>

<br/>

<asp:Labelid="Message"runat="server"width="80%"forecolor="red"enableviewstate="false"></asp:Label>ý

</form>

</

body>

</

html>


Cette discussion est classée dans : asp, end, string, datagrid, object


Répondre à ce message

Sujets en rapport avec ce message

ASP et InterDev [ par björk ] J'essaye de sortir des données qui sont sous Oracle avec InterDev, et voici ce que j'obtiens:Server Object error 'ASP 0177:800401f3'Server.Create Obje asp/Access, tant qu'y a du string ca va, mais apres... [ par droppy ] bonjour, voila je fais un formulaire html utilisant une fiche asp pour ecrire sur une base access. tout va bien pour les strings mais je ne sais pas c En ASP.net, les datagrid et autres outils du genre sont ils inévitables ? [ par BigJim ] La question vient du fait que je code à la main la plupart du temps, même si j'utilise Dreamweaver pour générer le code HTML "standard".L'écriture man liberer une instance de classe (asp) [ par titomcmoi ] Bonjour,Je voudrais savoir s'il existe une fonction asp qui permet de liberer la memoire (i.e: free en C ou delete en Cpp).Voila un resume de mon cod [ASP.NET] probleme avec session_end() [ par teug ] Bonjour,Lorsqu'une session se termine, la fonctione session_end() du fichier global.asax est censée être appelée...Chez moi, elle n'est jamais appelée Comparaison de string en ASP [ par guiguimac ] bonjour, ma question concerne l'ASP (tout court)j'aimerai savoir comment il est possible de comparer deux variable textemerci ! Pb fichier 500-100.asp [ par titine71 ] Bjr,j'ai un soucis avec le fichier 500-100.asp du serveur local.J'ai modifier toutes les erreurs de retour chariot, mais j'ai toujours cette erreur qu combobox et évènement onChange en ASP [ par lordskyser1 ] Je suis en train de développer un site pour un intranet. J'ai un formulaire d'ajout de sutilisateurs qui comporte un certain nombre de champs de texte Meilleur formattage des résultats sous datagrid [ par kozher20 ] Bonjour à tous, (P.S. Excusez-moi, j'ai posté par erreur ce même message dans la section Active X)Après ASP, je me met à ASP NET. Je suis en train de Récupérer une valeur d'un Control User acsx dans un Label [ par ryckbosch ] Bonjour,Je ne sais pas si j'utilise correctement le passage des variables entre un Control User (Nbre_Sites.ascx) et la page qui l'appelle (Test.aspx)


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,328 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales