Sort ASP.NET - ASP - Programmation
Marsh Posté le 04-06-2003 à 01:27:41
Pour l'instant j'ai mon SQLHelper qui me lance les données dans la datagrid
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("Customers" ) = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings.Get("con" ), CommandType.Text, "SELECT * FROM Customers" )
DataGrid1.DataSource = Session("Customers" )
DataGrid1.DataBind()
End Sub
J'ai ajouter dans les propriété City et CustomerID
ensuite j ai trouvé ca comme code
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
Dim dv As DataView
Dim ds As DataSet = Session("ds" )
If e.SortExpression = "CustomerID" Then
dv = ds.Tables(0).DefaultView
dv.Sort = "employeeID"
Else
dv = ds.Tables(0).DefaultView
dv.Sort = "City"
End If
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
Public Sub PageIndexChanged(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataSource = Session("ds" )
DataGrid1.DataBind()
End Sub
Maise ca me fait une erreur lorsque je clique sur le id ou le city pour trier :
Object reference not set to an instance of an object.
dv.Sort = "employeeID"
Line 44: Else
Line 45: dv = ds.Tables(0).DefaultView
Line 46: dv.Sort = "City"
Please Help
Marsh Posté le 04-06-2003 à 12:26:23
Bon j ai trouvé qqche qui fonctionne avec un Sqlhelper
Imports Microsoft.ApplicationBlocks.Data
Imports System
Imports System.Collections
Imports System.Data
Imports System.Web
Imports System.Web.UI.WebControls
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
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
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("Customers" ) = SQLhelper.ExecuteDataset(ConfigurationSettings.AppSettings.Get("con" ), CommandType.Text, "SELECT * FROM Customers" )
DataGrid1.DataSource = Session("Customers" )
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_SortCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
Dim dv As DataView
dv = New DataView(CType(Session("Customers" ), DataSet).Tables(0))
dv.Sort = e.SortExpression
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
End Class
Pour ceux que ca intéresse
Marsh Posté le 04-06-2003 à 01:14:47
Hello,
Comment on fait pour trier une ou deux colonne d'un datagrid sur Asp.Net je tourne en rond depuis 3h ca marche pas
Merci d'avance
---------------
Le Smiley de la mort !! (8÷þ