Trier un datagrid

Signaler
Messages postés
127
Date d'inscription
vendredi 21 janvier 2005
Statut
Membre
Dernière intervention
29 mai 2014
-
Messages postés
35
Date d'inscription
mardi 30 septembre 2003
Statut
Membre
Dernière intervention
7 mars 2005
-
Salut! J'essai de trier un datagrid en cliquant sur le header des colonne mais j'ai lerreure suivante ...


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 68: Private Sub dg_SortCommand(ByVal source As Object, ByVal e As DataGridSortCommandEventArgs) Handles dg.SortCommand
Line 69: Dim dv As DataView = Session("dv")
Line 70: dv.Sort = e.SortExpression
Line 71: DataBind()
Line 72:



voici mon code



Dim cn
As
New Odbc.OdbcConnection("DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\Inetpub\wwwroot\annuaire\annuaire.mdb")



Dim ds
As
New DataSet



Private
Sub Page_Load(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles
MyBase.Load



'Put user code to initialize the page here



Dim da
As
New Odbc.OdbcDataAdapter("select * from personnes", cn)


da.Fill(ds)


dg.DataSource = ds


dg.DataBind()












End
Sub



Private
Sub cmdRecherche_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles cmdRecherche.Click



Dim dt
As DataTable = ds.Tables(0)



Dim dv
As
New DataView(dt)



If RdoNom.Checked
Then


dv.RowFilter =
String.Format("nom like '{0}%'", txtRecherche.Text)



Else : dv.RowFilter =
String.Format("prenom like '{0}%'", txtRecherche.Text)



End
If


Session("dv") = dv


dg.DataSource = Session("dv")


dg.DataBind()









End
Sub



Private
Sub dg_PageIndexChanged(
ByVal source
As
Object,
ByVal e
As DataGridPageChangedEventArgs)
Handles dg.PageIndexChanged


dg.CurrentPageIndex = e.NewPageIndex


DataBind()



End
Sub



Private
Sub dg_SortCommand(
ByVal source
As
Object,
ByVal e
As DataGridSortCommandEventArgs)
Handles dg.SortCommand



Dim dv
As DataView = Session("dv")


dv.Sort = e.SortExpression


DataBind()






End
Sub

Merci

1 réponse

Messages postés
35
Date d'inscription
mardi 30 septembre 2003
Statut
Membre
Dernière intervention
7 mars 2005

a tu vérifier par hasart que tu autorise les variables session ??