drivign me crazy for last 2 days - itemdatabound

S

samir dsf

hi
i have a link in the datagrid which are actually the names of the
files..what i am doign is when i click to that link i display the
description of that file below it. i have implemented something simialr
before.

the problem now is that when i click the link my datagrid jsut vanishes.

ran thru the debugger...after i click the link it comes to the
dgFiles_ItemCommand then this condition "ElseIf (e.CommandName =
"ShowContent") Then" is satisfied to is goes to the bindGrid; from bind
grid it goes to ==>
dgFiles_ItemDataBound
here is just repeates the dgFiles_ItemDataBound event only 2ice. once
for header and once for footer.

why is this happening..why does the datagird only have header and
footer?

Private Sub dgFiles_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgFiles.ItemCommand

If e.CommandName = "File" Then

/////
ElseIf e.CommandName = "Delete" Then
////
ElseIf (e.CommandName = "ShowContent") Then 'this is what is causing
problem

dgFiles.EditItemIndex = e.Item.ItemIndex
bindGrid()

End If
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 As System.Web.UI.WebControls.Label
lbl = e.Item.FindControl("lblSize")
FilePath = e.Item.Cells(1).Text
filename = e.Item.Cells(2).Text
Dim fi As FileInfo = New FileInfo(FilePath & filename)
Dim fileBytes As Integer = (fi.Length / 1024)
lbl.Text = fileBytes.ToString
End If
If e.Item.ItemType =
System.Web.UI.WebControls.ListItemType.AlternatingItem Or
e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Item Then
Dim link As System.Web.UI.WebControls.LinkButton =
CType(e.Item.FindControl("select"),
System.Web.UI.WebControls.LinkButton)
link.Text = e.Item.Cells(2).Text
End If
Dim itemType As System.Web.UI.WebControls.ListItemType =
e.Item.ItemType
If (e.Item.ItemType =
System.Web.UI.WebControls.ListItemType.EditItem) Then
Dim row As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim title As System.Web.UI.WebControls.Label =
CType(e.Item.FindControl("Title"), System.Web.UI.WebControls.Label)
Dim content As System.Web.UI.WebControls.Label =
CType(e.Item.FindControl("content"), System.Web.UI.WebControls.Label)
title.Text = row("FILENAME").ToString()
Dim contentStr As String = ByteArrayToString(row("DESCRIPTION"))
content.Text = contentStr
End If
End Sub
 
S

Siva M

I am not sure what bindGrid() does when it is called in the 'ShowContent'
part. Probably, showing bindGrid() code will help.


hi
i have a link in the datagrid which are actually the names of the
files..what i am doign is when i click to that link i display the
description of that file below it. i have implemented something simialr
before.

the problem now is that when i click the link my datagrid jsut vanishes.

ran thru the debugger...after i click the link it comes to the
dgFiles_ItemCommand then this condition "ElseIf (e.CommandName =
"ShowContent") Then" is satisfied to is goes to the bindGrid; from bind
grid it goes to ==>
dgFiles_ItemDataBound
here is just repeates the dgFiles_ItemDataBound event only 2ice. once
for header and once for footer.

why is this happening..why does the datagird only have header and
footer?

Private Sub dgFiles_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgFiles.ItemCommand

If e.CommandName = "File" Then

/////
ElseIf e.CommandName = "Delete" Then
////
ElseIf (e.CommandName = "ShowContent") Then 'this is what is causing
problem

dgFiles.EditItemIndex = e.Item.ItemIndex
bindGrid()

End If
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 As System.Web.UI.WebControls.Label
lbl = e.Item.FindControl("lblSize")
FilePath = e.Item.Cells(1).Text
filename = e.Item.Cells(2).Text
Dim fi As FileInfo = New FileInfo(FilePath & filename)
Dim fileBytes As Integer = (fi.Length / 1024)
lbl.Text = fileBytes.ToString
End If
If e.Item.ItemType =
System.Web.UI.WebControls.ListItemType.AlternatingItem Or
e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Item Then
Dim link As System.Web.UI.WebControls.LinkButton =
CType(e.Item.FindControl("select"),
System.Web.UI.WebControls.LinkButton)
link.Text = e.Item.Cells(2).Text
End If
Dim itemType As System.Web.UI.WebControls.ListItemType =
e.Item.ItemType
If (e.Item.ItemType =
System.Web.UI.WebControls.ListItemType.EditItem) Then
Dim row As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim title As System.Web.UI.WebControls.Label =
CType(e.Item.FindControl("Title"), System.Web.UI.WebControls.Label)
Dim content As System.Web.UI.WebControls.Label =
CType(e.Item.FindControl("content"), System.Web.UI.WebControls.Label)
title.Text = row("FILENAME").ToString()
Dim contentStr As String = ByteArrayToString(row("DESCRIPTION"))
content.Text = contentStr
End If
End Sub
 
S

samir dsf

here is my bindgrid

Public Sub bindGrid()
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 FROM DOWNLOADFILES WHERE
@lower(ORGANISATION)=@lower('" & Orgn & "') and FILEREPORT='FILE' "

'CHECK WHAT APPLICATION TYPES AND SERVICES ARE CHOSEN BY
THIS USER
strSQL2 = "select
DESKTOP,NETWORK,DATACENTRE,PREMIUM,SERVER,HELPDESK FROM SERVICETYPES
where @lower(USERNAME) = @lower('" & Session("GlobalUserName") & "')"
objCommand = New OleDbCommand(strSQL2, objConnection)
objReaderServiceType = objCommand.ExecuteReader()
Dim flagCONCAT As Boolean = False
Dim endSQL As String
While (objReaderServiceType.Read())

If objReaderServiceType("DESKTOP") = 1 Or
objReaderServiceType("DATACENTRE") = 1 Or _
objReaderServiceType("PREMIUM") = 1 Or
objReaderServiceType("SERVER") = 1 Or _
objReaderServiceType("HELPDESK") = 1 Or
objReaderServiceType("NETWORK") = 1 Then
Dim startSQL As String = " AND ("
endSQL = " ) "
flagCONCAT = True
strSQL = strSQL & startSQL
End If
Dim flagOR As Boolean = False
Dim midSQL As String = " OR "
If objReaderServiceType("DESKTOP") = 1 Then
flagOR = True
strSQL = strSQL & " APPSERVICETYPE='DESKTOP'"
End If
If objReaderServiceType("DATACENTRE") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='DATACENTRE'"
End If
If objReaderServiceType("PREMIUM") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='PREMIUM'"
End If
If objReaderServiceType("SERVER") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='SERVER'"
End If
If objReaderServiceType("HELPDESK") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='HELPDESK'"
End If
If objReaderServiceType("NETWORK") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='NETWORK'"
End If
End While
If flagCONCAT = True Then
strSQL = strSQL & endSQL
End If
objReaderServiceType.Close()
GoToDBCloseConn()
If flagCONCAT = True Then
GoToDBOpenConn()
objCommand = New OleDbCommand(strSQL, objConnection)
myDa.SelectCommand = objCommand
Dim dt As New DataTable
myDa.Fill(dt)
Me.dgFiles.DataSource = dt
Me.dgFiles.DataBind()

End If


Catch ex As Exception
lblError.Text = "bindGrid(): " & ex.Message.ToString
Finally
GoToDBCloseConn()
End Try
End Sub
 
S

samir dsf

only problem now is that when i click the link ... i dont see the
datagrid at all..

so it means the datasource is not being provided. but i ran thru the
debugger

after i click the link it comes to the
dgFiles_ItemCommand then this condition "ElseIf (e.CommandName =
"ShowContent") Then" is satisfied to is goes to the bindGrid; from bind
grid it goes to ==>
dgFiles_ItemDataBound
here is just repeates the dgFiles_ItemDataBound event only 2ice. once
for header and once for footer.

why is this happening..why si the datagird empty?
 
S

Siva M

Hi,

bindGrid() looks ok to me. Probably, you might want to execute the SQL query
constructed by this procedure separately and check that you are getting one
or more rows.

here is my bindgrid

Public Sub bindGrid()
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 FROM DOWNLOADFILES WHERE
@lower(ORGANISATION)=@lower('" & Orgn & "') and FILEREPORT='FILE' "

'CHECK WHAT APPLICATION TYPES AND SERVICES ARE CHOSEN BY
THIS USER
strSQL2 = "select
DESKTOP,NETWORK,DATACENTRE,PREMIUM,SERVER,HELPDESK FROM SERVICETYPES
where @lower(USERNAME) = @lower('" & Session("GlobalUserName") & "')"
objCommand = New OleDbCommand(strSQL2, objConnection)
objReaderServiceType = objCommand.ExecuteReader()
Dim flagCONCAT As Boolean = False
Dim endSQL As String
While (objReaderServiceType.Read())

If objReaderServiceType("DESKTOP") = 1 Or
objReaderServiceType("DATACENTRE") = 1 Or _
objReaderServiceType("PREMIUM") = 1 Or
objReaderServiceType("SERVER") = 1 Or _
objReaderServiceType("HELPDESK") = 1 Or
objReaderServiceType("NETWORK") = 1 Then
Dim startSQL As String = " AND ("
endSQL = " ) "
flagCONCAT = True
strSQL = strSQL & startSQL
End If
Dim flagOR As Boolean = False
Dim midSQL As String = " OR "
If objReaderServiceType("DESKTOP") = 1 Then
flagOR = True
strSQL = strSQL & " APPSERVICETYPE='DESKTOP'"
End If
If objReaderServiceType("DATACENTRE") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='DATACENTRE'"
End If
If objReaderServiceType("PREMIUM") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='PREMIUM'"
End If
If objReaderServiceType("SERVER") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='SERVER'"
End If
If objReaderServiceType("HELPDESK") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='HELPDESK'"
End If
If objReaderServiceType("NETWORK") = 1 Then
If flagOR = True Then
strSQL = strSQL & midSQL
Else
flagOR = True
End If
strSQL = strSQL & " APPSERVICETYPE='NETWORK'"
End If
End While
If flagCONCAT = True Then
strSQL = strSQL & endSQL
End If
objReaderServiceType.Close()
GoToDBCloseConn()
If flagCONCAT = True Then
GoToDBOpenConn()
objCommand = New OleDbCommand(strSQL, objConnection)
myDa.SelectCommand = objCommand
Dim dt As New DataTable
myDa.Fill(dt)
Me.dgFiles.DataSource = dt
Me.dgFiles.DataBind()

End If


Catch ex As Exception
lblError.Text = "bindGrid(): " & ex.Message.ToString
Finally
GoToDBCloseConn()
End Try
End Sub
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top