I am trying to sort my second datagrid. And it works but only after i
click 2 times on the column header. The first time i click on the
header the data in the right order will add to the rows in the
datagrid. The second time i click on the header the top halve changes
in the right order too.
What i do wrong?
btw if i remove PlaatsVoetballe rs in the sub sorteergrid the first
click it does nothing the second time it sorts (no adding new rows)
Sorry for all the dutch in the code
my code
Private objDataset As DataSet = New System.Data.Dat aSet()
Private sConnectionStri ng As String =
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "\WebApplicatio n1\data\TestMeg aDB.mdb") & ";"
Protected WithEvents dgClubs As System.Web.UI.W ebControls.Data Grid
Protected WithEvents dgVoetballers As
System.Web.UI.W ebControls.Data Grid
Private objConnection As OleDbConnection = New
OleDbConnection (sConnectionStr ing)
Protected WithEvents lblSorteer As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblCount As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Dim test As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
lblSorteer.Text = "VoetballerNaam "
objConnection.O pen()
Dim sSQl As String = "Select * from Clubs where ClubNaam
<> 'Geen voetballer' order by ClubNaam"
Dim ObjCommand As OleDbCommand = New OleDbCommand(sS Ql,
objConnection)
Dim objDatareader As OleDbDataReader
objDatareader =
ObjCommand.Exec uteReader(Comma ndBehavior.Clos eConnection)
dgClubs.DataSou rce = objDatareader
dgClubs.DataBin d()
objDatareader.C lose()
End If
PlaatsVoetballe rs()
End Sub
Private Sub PlaatsVoetballe rs()
Dim sSQl2 As String = "Select VoetballerNaam,
VoetballerPosit ie from Voetballers where ClubID = 1 order by " &
lblSorteer.Text
'Dim sSQl2 As String = "Select VoetballerNaam,
VoetballerPosit ie from Voetballers where ClubID = 1 order by
VoetballerNaam"
Dim objDataAdapter As New OleDbDataAdapte r(sSQl2,
objConnection)
lblCount.Text = sSQl2
objDataAdapter. Fill(objDataset , "Voetballer s")
dgVoetballers.D ataSource = objDataset
dgVoetballers.D ataMember = "Voetballer s"
dgVoetballers.D ataBind()
VerwerkVoetball ersInGrid()
End Sub
Private Sub VerwerkVoetball ersInGrid()
Dim iRecords As Integer
For iRecords = 0 To dgVoetballers.I tems.Count - 1
Select Case dgVoetballers.I tems(iRecords). Cells(1).Text
Case 1
dgVoetballers.I tems(iRecords). Cells(1).Text =
"Keeper"
Case 2
dgVoetballers.I tems(iRecords). Cells(1).Text =
"Verdediger "
Case 3
dgVoetballers.I tems(iRecords). Cells(1).Text =
"Middenveld er"
Case 4
dgVoetballers.I tems(iRecords). Cells(1).Text =
"Aanvaller"
Case 5
dgVoetballers.I tems(iRecords). Cells(1).Text =
"Coach"
End Select
Next
End Sub
Sub clubclicked(ByV al sender As Object, ByVal e As
DataGridCommand EventArgs)
Dim buttontest As TableCell = e.Item.Cells(1)
Dim buttonstring As String = buttontest.Text
End Sub
Sub VerwijderCollum s(ByVal s As Object, ByVal e As
DataGridItemEve ntArgs)
e.Item.Cells(1) .Visible = False
e.Item.Cells(2) .Visible = False
End Sub
Sub SorteerGrid(ByV al sender As Object, ByVal e As
DataGridSortCom mandEventArgs)
lblSorteer.Text = e.SortExpressio n.ToString()
PlaatsVoetballe rs()
End Sub
<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="Spe lerOverzicht.as px.vb"
Inherits="WebAp plication1.WebF orm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta content="Micros oft Visual Studio.NET 7.0" name="GENERATOR ">
<meta content="Visual Basic 7.0" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body bgColor="#fffff f" MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgClubs" style="Z-INDEX: 101; LEFT: 6px;
POSITION: absolute; TOP: 2px" runat="server" Height="116px"
Width="188px" BackColor="Lime Green" BorderColor="Bl ack"
BorderStyle="So lid" ShowHeader="Fal se" OnItemCommand=" clubclicked"
OnItemDataBound ="VerwijderColl ums" Font-Bold="True"
Font-Names="Century Gothic">
<Columns>
<asp:ButtonColu mn DataTextField=" ClubNaam">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:ButtonColum n>
</Columns>
</asp:datagrid><a sp:label id="lblSorteer " style="Z-INDEX: 102;
LEFT: 24px; POSITION: absolute; TOP: 163px" runat="server"
Height="6px" Width="76px">17 </asp:label><asp: datagrid
id="dgVoetballe rs" style="Z-INDEX: 103; LEFT: 205px; POSITION:
absolute; TOP: -3px" runat="server" Height="392px" Width="272px"
AllowSorting="T rue" OnSortCommand=" SorteerGrid"></asp:datagrid><a sp:label
id="lblCount" style="Z-INDEX: 104; LEFT: 506px; POSITION: absolute;
TOP: 63px" runat="server" Height="13px" Width="361px">0 </asp:label>
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 524px; POSITION:
absolute; TOP: 123px" runat="server" Height="24px"
Width="58px">La bel</asp:Label></form>
</body>
</HTML>