By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

Paranormal DataGrid Sorting

P: n/a
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got
a mystery with a DataGrid. Below is the definition of the DataGrid
from my aspx page:

</asp:datagrid><asp:datagrid id="dgDetails" Runat="server"
Width="100%" Visible="False" AllowSorting="True" CellPadding="1"
CellSpacing="0" AutoGenerateColumns="False"
OnSortCommand="SortDetails">
<ItemStyle Font-Size="XX-Small" Font-Names="Tahoma"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Tahoma"
Font-Bold="True" HorizontalAlign="Center" ForeColor="#DADEFE"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Seq" ItemStyle-Width="5%"
SortExpression="Ignore">
<ItemTemplate>
<asp:TextBox ID="txtSeqTab2" Runat="server"
Font-Names="Tahoma" Font-Size="X-Small" Width="35"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="OCDTE" HeaderText="Due"
SortExpression="OCDTE"></asp:BoundColumn>
<asp:BoundColumn DataField="OWRKC" HeaderText="WC"
SortExpression="OWRKC"></asp:BoundColumn>
<asp:BoundColumn DataField="OORD" HeaderText="SO"
SortExpression="OORD"></asp:BoundColumn>
<asp:BoundColumn DataField="OOPNO" HeaderText="Op"
SortExpression="OOPNO"></asp:BoundColumn>
<asp:BoundColumn DataField="OOPDS" HeaderText="Description"
SortExpression="OOPDS"></asp:BoundColumn>
<asp:BoundColumn DataField="Quantity" HeaderText="Reqd"
SortExpression="Quantity"></asp:BoundColumn>
<asp:BoundColumn DataField="PostQty" HeaderText="Posted"
SortExpression="PostQty"></asp:BoundColumn>
<asp:BoundColumn DataField="ODPRD" HeaderText="Item"
SortExpression="ODPRD"></asp:BoundColumn>
<asp:BoundColumn DataField="OMAC" HeaderText="Hrs"
SortExpression="OMAC"></asp:BoundColumn>
<asp:BoundColumn DataField="Notes" HeaderText="Notes"
SortExpression="Notes"></asp:BoundColumn>
<asp:BoundColumn Visible="False"
SortExpression="Ignore"></asp:BoundColumn>
<asp:BoundColumn Visible="False"
SortExpression="Ignore"></asp:BoundColumn>
<asp:BoundColumn Visible="False"
SortExpression="Ignore"></asp:BoundColumn>
</Columns>
</asp:datagrid>

As you can see, I've told it to allow sorting, and I've provided a
sort expression for each column. The last three columns are not
displayed as these are for the user to add a column and select what
field should be displayed there if they desire even more data. I
simply make a column visible when they click on the Add Column button.
So, I have to bind these later, if they are used, to the field that
they will then represent. The DataGrid is being populated in the
following manner from my VB code behind page:

strSQL = "SELECT OCDTE, OWRKC, OORD, OOPNO, OOPDS, Case When
Package_Flag <> 'Y' "
strSQL += "Then OQty * MFG_UNITS_PER_PACK Else OQty End as Quantity,
Case When Package_Flag <> 'Y' "
strSQL += "Then OQTYP * MFG_UNITS_PER_PACK Else OQTYP End as PostQty,
ODPRD, OMAC, STRIP(SOCOMM) As Notes, "
strSQL += "OSET FROM V40BPCSF.FOD A JOIN V40BPCSUSF.IIEP001 B ON
B.IEPROD = A.ODPRD JOIN "
strSQL += "V40BPCSUSF.FTEL002 ON A.OOPDS = V40BPCSUSF.FTEL002.IDESCE
JOIN V40BPCSUSF.FSOP001 ON "
strSQL += "A.OORD = V40BPCSUSF.FSOP001.SOORD WHERE A.OCMPL <> 'Y' AND
A.ODID = 'OD' "
strSQL += "AND A.OWRKC NOT IN(995, 996, 997, 998, 999) "
strSQL += "AND A.OCDTE <= " & Format(baseDate.AddDays(25), "yyyyMMdd")
& " "
strSQL += "ORDER BY A.OCDTE, A.OORD"
da = New OleDbDataAdapter(strSQL, objConnection)
da.Fill(ds, "Details")

dv = ds.Tables("Details").DefaultView()
dv.Sort = "OCDTE"
dgDetails.DataSource = dv
dgDetails.DataBind()

I know it's a long SQL statement, but it gets what we need. ;-) My
data is then displayed in my browser with nice hyperlink column names
that can be clicked to sort based on that column. Below is my sort
sub:

Public Sub SortDetails(ByVal sender As Object, ByVal e As
DataGridSortCommandEventArgs)
Dim strSortExp As String = e.SortExpression.ToString()
Dim dv As DataView

If strSortExp = "Ignore" Then
Exit Sub
End If

dv = CType(Session.Item("Details_Table_" &
Session.SessionID.ToString()), DataTable).DefaultView()
dv.Sort = strSortExp
dgDetails.DataSource = dv
dgDetails.DataBind()
End Sub

The "Ignore" sort expression is for my three invisible columns until I
figure out what and how to do what I need to with them. My problem is
that I will click on one column heading, say "Item" which should
return a sort expression of "ODPRD". However, while debugging, I look
at strSortExp in my SortDetails Sub and the DataGrid has actually sent
back "OOPDS" or the Description column for my sort expression. When I
get presented my data again, .NET has sorted on Description and not
Item which I clicked. This does not always happen. It happens about
33% to 50% of the time. What's going on here? Does anyone see anything
in my code that could be causing such weird behavior? Sorry for the
long post. I just want everyone to have all of the relevant info.
Thanks in advance for any help.

Robert
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.