urgent going crazy data not getting sorted!

S

samir25

hi

here is a part of my datagrid itembound event where i calculate 2
columns and assign values to the columns
Dim fileBytes As Integer = (fi.Length / 1024)
Dim lastmodifeddt As Date = File.GetLastWriteTime(FilePath & filename)
lastmodifeddt = lastmodifeddt.Date
lbl.Text = fileBytes
lbl2.Text = lastmodifeddt.ToString("dd MMM yyyy")

and here is my sort function:
strSQL = "select FILEID, FILENAME, APPSERVICETYPE,LOCATION,FILEREPORT,
DESCRIPTION, location2 FROM DOWNLOADFILES WHERE
(@lower(ORGANISATION)=@lower('" & Session("Orgn") & "') or
@lower(ORGANISATION)='mewha') and FILEREPORT='REPORT'"
GoToDBOpenConn()
myDa.SelectCommand = New System.Data.OleDb.OleDbCommand(strSQL,
objConnection)
myDa.Fill(myDS)
myDS.Tables(0).Columns.Add("lbl2")
myDS.Tables(0).Columns.Add("lbl")
Dim objView As New DataView(myDS.Tables(0))
objView.Sort = E.SortExpression() & " DESC"
dgFiles.DataSource = objView
dgFiles.DataBind()

everythign is fine ... only that when i click to the sort of the
calculated columns they dont work

when i sort by lbl...which is size here...here is what i get

Category Description Size(KB) Last Modified
SERVER ensuring 73 Aug 23, 2005
SERVER bullying 92 Aug 23, 2005
DESKTOP sql engg 397 Jul 28, 2005
SERVER portal users 18 Nov 22, 2005
DESKTOP relnote 117 Dec 11, 2002

and when i sort by the last modified column here is what i get (this is
lbl2)
Category Description Size(KB) Last Modified
SERVER ensuring 73 Aug 23, 2005
SERVER bullying 92 Aug 23, 2005
DESKTOP sql engg 397 Jul 28, 2005
SERVER portal users 18 Nov 22, 2005
DESKTOP relnote 117 Dec 11, 2002

both the things are not working. its madening!but category
works...maybe bec its a db column why is this happ?
thanks for helping on this
 
A

addup

It may be simpler than you think

First - how are the values for these columns calulated?
myDS.Tables(0).Columns.Add("lbl2")
myDS.Tables(0).Columns.Add("lbl")

If I have read your code right, the two *columns* lbl and lbl2 that you
sort on have no values!

The *controls* lbl and lbl2 (in your template ?) are being populated at
datagrid itembound event which is fired once for every row, AFTER the
databind (see? the order of the rows has already been decided at this
point!)

post a complete, simplified, page and we can help pinnpoint the trouble

Hope this helps
-- addup --
 
S

samir25

hey thanks for responding. i hope you are still available to guide me
further on this.

here is my ascx part:
<asp:TemplateColumn HeaderText="Size(KB)"
HeaderStyle-CssClass="SubHead" SortExpression="lbl">
<ItemTemplate>
<asp:Label Runat="server" ID="lblSize"
CssClass="SubHead"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="FileID"
Visible="False"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Last Modified"
HeaderStyle-CssClass="SubHead" SortExpression="lbl2">
<ItemTemplate>
<asp:Label Runat="server" ID="lblMdDate"
CssClass="SubHead"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

my page load event==>

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
GlobalUserName = UserInfo.Username
Session("GlobalUserName") = GlobalUserName
If Not Me.IsPostBack Then
GetDeptOfUserLogged()
strSQL = "select FILEID, FILENAME,
APPSERVICETYPE,LOCATION,FILEREPORT, DESCRIPTION, location2 FROM
DOWNLOADFILES WHERE (@lower(ORGANISATION)=@lower('" & Session("Orgn") &
"') or @lower(ORGANISATION)='merha') and FILEREPORT='REPORT' order by
APPSERVICETYPE, FILENAME "
bindGrid2()
End If
End Sub
Public Sub bindGrid2()
Try
'CheckValidate
Page.Validate()
If Not Page.IsValid Then
Return
End If
'get details from the db
GoToDBOpenConn()
strSQL = "select FILEID,
FILENAME,APPSERVICETYPE,LOCATION,FILEREPORT, DESCRIPTION, location2
FROM DOWNLOADFILES WHERE (@lower(ORGANISATION)=@lower('" & Orgn & "')
or @lower(ORGANISATION)='merha') and FILEREPORT='REPORT' order by
APPSERVICETYPE, FILENAME "
objCommand = New OleDbCommand(strSQL, objConnection)
myDa.SelectCommand = objCommand
Dim dt As New DataTable
myDa.Fill(dt)
Me.dgFiles.DataSource = dt
Me.dgFiles.DataBind()
Catch ex As Exception
lblError.Text = "bindGrid(): " & ex.Message.ToString
Finally
GoToDBCloseConn()
End Try
End Sub

my sort event ==>

Sub SortCommand_OnClick(ByVal Source As Object, ByVal E As
System.Web.UI.WebControls.DataGridSortCommandEventArgs)
strSQL = "select FILEID, FILENAME,
APPSERVICETYPE,LOCATION,FILEREPORT, DESCRIPTION, location2 FROM
DOWNLOADFILES WHERE (@lower(ORGANISATION)=@lower('" & Session("Orgn") &
"') or @lower(ORGANISATION)='mha') and FILEREPORT='REPORT'"
GoToDBOpenConn()
myDa.SelectCommand = New
System.Data.OleDb.OleDbCommand(strSQL, objConnection)
myDa.Fill(myDS)
' myDS.Tables.Add(0)
myDS.Tables(0).Columns.Add(New DataColumn("lbl2",
System.Type.GetType("System.DateTime")))
myDS.Tables(0).Columns.Add(New DataColumn("lbl",
System.Type.GetType("System.Int32")))
'myDS.Tables(0).Columns.Add("lbl2")
'myDS.Tables(0).Columns.Add("lbl")
Dim objView As New DataView(myDS.Tables(0))
objView.Sort = E.SortExpression() & " DESC"
dgFiles.DataSource = objView
dgFiles.DataBind()
End Sub

my itembound event==>

Private Sub dgFiles_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgFiles.ItemDataBound
If e.Item.ItemType =
System.Web.UI.WebControls.ListItemType.AlternatingItem Or
e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Item Or
e.Item.ItemType = System.Web.UI.WebControls.ListItemType.EditItem Then
Dim lbl, lbl2 As System.Web.UI.WebControls.Label
Dim row As DataRowView = CType(e.Item.DataItem,
DataRowView)
lbl = e.Item.FindControl("lblSize")
lbl2 = e.Item.FindControl("lblMdDate")
Dim phyPath As String
phyPath =
Server.MapPath(ByteArrayToString(row("LOCATION")))
e.Item.Cells(2).Text = phyPath
FilePath = e.Item.Cells(2).Text
filename = e.Item.Cells(3).Text
Dim fi As FileInfo = New FileInfo(FilePath & filename)
Dim fileBytes As Integer = (fi.Length / 1024)
Dim lastmodifeddt As DateTime =
File.GetLastWriteTime(FilePath & filename)
'lastmodifeddt = lastmodifeddt.Date
lbl.Text = fileBytes
lbl2.Text = lastmodifeddt.ToShortDateString
'.ToString("dd MMM yyyy")
Dim urlParams As String = "FileID=" +
row("FILEID").ToString()
Dim tabid As Int32 = 185 'row("TABID1")
e.Item.Cells(4).Text = "<A href='" &
DotNetNuke.Common.Globals.NavigateURL(tabid, "", urlParams) & "'
target=""_parent"">" + ByteArrayToString(row("DESCRIPTION")) & "</A>"
End If
End Sub

thanks again for responding.
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top