View Single Post
  #28 (permalink)  
Old 08-08-2007, 06:20 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

Given below is some of my code:

Private Sub projectGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

' Use the RowType property to determine whether the

' row being created is the header row.

If (e.Row.RowType = DataControlRowType.Header) Then
For i As Integer = 0 To e.Row.Cells.Count - 1

' Create the sorting image based on the sort direction.
Dim sortImage As Image = New Image

'Test whether or not session is exist

If Session(projectGridView.Columns(i).SortExpression) Is Nothing Or Session(projectGridView.Columns(i).SortExpression) = "ASC" Then

sortImage.ImageUrl = "../images/arrow_up.gif"

sortImage.AlternateText = "Ascending Order"

Else

sortImage.ImageUrl = "../images/arrow_down.gif"

sortImage.AlternateText = "Descending Order"

End If

' Add the image to the appropriate header cell.
e.Row.Cells(i).Controls.Add(New LiteralControl(" "))

e.Row.Cells(i).Controls.Add(sortImage)

Next

End If

If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim attachmentImage As Image = New Image
attachmentImage.ImageUrl = "../images/paperclip.gif"
attachmentImage.AlternateText = "Attachment"
'Dim fileName As String
If projectGridView.Columns(0).HeaderText = "ID" Then
Dim connString As String
Dim con As SqlConnection


Try
connString = System.Web.Configuration.WebConfigurationManager.C onnectionStrings("ConnectionString1").ConnectionSt ring

con = New SqlConnection(connString)

Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = con

cmd.CommandText = "dbo.GetOpenProjectInfo"
cmd.CommandType = CommandType.StoredProcedure

Dim adapter As New SqlDataAdapter(cmd)

Dim proj As New DataSet
adapter.Fill(proj, "Projects")

'Response.Write(proj.Tables(0).Rows.Count & " ")
'Response.Write(proj.Tables(0).Columns.Count & " ")
If Not [String].IsNullOrEmpty(e.Row.Cells(0).ToString) Then
Dim i
Dim fileURL As String
Dim dr As DataRow
dr = proj.Tables(0).Rows(e.Row.RowIndex)
If [String].IsNullOrEmpty(dr.Item("FileName").ToString) = False Then
fileURL = Server.MapPath(".") & "\upload\" & dr("FileName").ToString
'Response.Write("    " & dr("FileName").ToString & "    ")
e.Row.Cells(0).Controls.Add(New LiteralControl("<a href=""" & fileURL & """>"))
e.Row.Cells(0).Controls.Add(attachmentImage)
e.Row.Cells(0).Controls.Add(New LiteralControl("</a>"))
End If
End If

'For i = 0 To ((proj.Tables(0).Rows.Count) - 1)

' Response.Write("<br />" & i & "<br />")
' Response.Write(dr.Item("FileName").ToString)

'Next i

'For Each dr As DataRow In proj.Tables(0).Rows
' If [String].IsNullOrEmpty(dr("FileName").ToString) = False Then
' Response.Write(dr("FileName").ToString & " &nbsp;&nbsp;&nbsp;")
' e.Row.Cells(0).Controls.Add(New LiteralControl(""))
' e.Row.Cells(0).Controls.Add(attachmentImage)
' End If
'Next dr

Try
con.Open()
cmd.ExecuteNonQuery()

Catch ex As Exception
Response.Write(ex)
Finally
con.Close()
con.Dispose()

End Try



Catch ex As ApplicationException
Response.Write("Could not load the database")
End Try
End If
End If

End Sub
Currently the items on RowIndex 1 and 2 have attachments. When the page loads, the attachments image shows up next the "ID" column in those rows.
Reply With Quote