datagrid sorting does something wierd

D

Danny

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 PlaatsVoetballers 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.DataSet()
Private sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("\WebApplication1\data\TestMegaDB.mdb") & ";"
Protected WithEvents dgClubs As System.Web.UI.WebControls.DataGrid
Protected WithEvents dgVoetballers As
System.Web.UI.WebControls.DataGrid
Private objConnection As OleDbConnection = New
OleDbConnection(sConnectionString)
Protected WithEvents lblSorteer As System.Web.UI.WebControls.Label
Protected WithEvents lblCount As System.Web.UI.WebControls.Label
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

Dim test As Integer

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

If Not Page.IsPostBack Then
lblSorteer.Text = "VoetballerNaam"

objConnection.Open()
Dim sSQl As String = "Select * from Clubs where ClubNaam
<> 'Geen voetballer' order by ClubNaam"
Dim ObjCommand As OleDbCommand = New OleDbCommand(sSQl,
objConnection)

Dim objDatareader As OleDbDataReader
objDatareader =
ObjCommand.ExecuteReader(CommandBehavior.CloseConnection)

dgClubs.DataSource = objDatareader
dgClubs.DataBind()
objDatareader.Close()


End If
PlaatsVoetballers()


End Sub

Private Sub PlaatsVoetballers()
Dim sSQl2 As String = "Select VoetballerNaam,
VoetballerPositie from Voetballers where ClubID = 1 order by " &
lblSorteer.Text
'Dim sSQl2 As String = "Select VoetballerNaam,
VoetballerPositie from Voetballers where ClubID = 1 order by
VoetballerNaam"

Dim objDataAdapter As New OleDbDataAdapter(sSQl2,
objConnection)

lblCount.Text = sSQl2
objDataAdapter.Fill(objDataset, "Voetballers")

dgVoetballers.DataSource = objDataset
dgVoetballers.DataMember = "Voetballers"
dgVoetballers.DataBind()


VerwerkVoetballersInGrid()

End Sub

Private Sub VerwerkVoetballersInGrid()
Dim iRecords As Integer
For iRecords = 0 To dgVoetballers.Items.Count - 1
Select Case dgVoetballers.Items(iRecords).Cells(1).Text
Case 1
dgVoetballers.Items(iRecords).Cells(1).Text =
"Keeper"
Case 2
dgVoetballers.Items(iRecords).Cells(1).Text =
"Verdediger"
Case 3
dgVoetballers.Items(iRecords).Cells(1).Text =
"Middenvelder"
Case 4
dgVoetballers.Items(iRecords).Cells(1).Text =
"Aanvaller"
Case 5
dgVoetballers.Items(iRecords).Cells(1).Text =
"Coach"
End Select
Next

End Sub

Sub clubclicked(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim buttontest As TableCell = e.Item.Cells(1)
Dim buttonstring As String = buttontest.Text

End Sub

Sub VerwijderCollums(ByVal s As Object, ByVal e As
DataGridItemEventArgs)
e.Item.Cells(1).Visible = False
e.Item.Cells(2).Visible = False

End Sub

Sub SorteerGrid(ByVal sender As Object, ByVal e As
DataGridSortCommandEventArgs)
lblSorteer.Text = e.SortExpression.ToString()
PlaatsVoetballers()

End Sub

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="SpelerOverzicht.aspx.vb"
Inherits="WebApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bgColor="#ffffff" 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="LimeGreen" BorderColor="Black"
BorderStyle="Solid" ShowHeader="False" OnItemCommand="clubclicked"
OnItemDataBound="VerwijderCollums" Font-Bold="True"
Font-Names="Century Gothic">
<Columns>
<asp:ButtonColumn DataTextField="ClubNaam">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid><asp: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="dgVoetballers" style="Z-INDEX: 103; LEFT: 205px; POSITION:
absolute; TOP: -3px" runat="server" Height="392px" Width="272px"
AllowSorting="True" OnSortCommand="SorteerGrid"></asp:datagrid><asp: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">Label</asp:Label></form>
</body>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top