Sir, i have a gridview that bind with Student Unique Id and Student Name with two file upload buttons. and show look like.
StudentID - StudentName - PhotoUpload - SignUpload
101 - Rajesh - fileuploadButton- fileuploadbutton
102 - Arun - fileuploadButton- fileuploadbutton
when i upload photo and sign of student in gridview and save it in sql server 2005 database. the following data are save in sql table
StudentID - UploadType
101 - photo
101 - Sign
102 - Sign
and photo Save in a folder with specific name like
'studentID≈P≈PhotoName' ex-
'101≈P≈rajeshphoto'. and same as Sign
'studentID≈S≈PhotoName' ex-
'101≈P≈rajeshSign'.
now i need that when i bind my gridview. then the color of thos file upload button column are change which are save in database. it means if a save 'rajesh' 'photo' then the color of fileupload button of photoUpload COlumn will be change.
my code are follow:-
Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim cmd As New SqlCommand With {.Connection = Hari.Utility.dbutility.Con}
For Each item As GridViewRow In GridView1.Rows
Dim StudentID As String = CType(GridView1.Rows(item.RowIndex).Cells(1).FindControl("LabelStudentID"), Label).Text
Dim photo As String = CType(GridView1.Rows(item.RowIndex).Cells(6).FindControl("FileUpload1"), FileUpload).FileName
Dim Sign As String = CType(GridView1.Rows(item.RowIndex).Cells(7).FindControl("FileUpload2"), FileUpload).FileName
If Not photo = "" Then
cmd.CommandText = "Insert into upload(StudentId,UploadType)Values(" & StudentID & ",'Photo') "
cmd.ExecuteNonQuery()
If CType(item.FindControl("FileUpload1"), FileUpload).HasFile Then
Dim fileName As String = StudentID + "≈" + "P" + "≈" + Path.GetFileName(CType(item.FindControl("FileUpload1"), FileUpload).PostedFile.FileName).ToString
CType(item.FindControl("FileUpload1"), FileUpload).PostedFile.SaveAs((Server.MapPath("~/photos/Photo/") + fileName))
End If
End If
If Not Sign = "" Then
cmd.CommandText = "Insert into upload(StudentId,UploadType)Values(" & StudentID & ",'Sign') "
cmd.ExecuteNonQuery()
If CType(item.FindControl("FileUpload2"), FileUpload).HasFile Then
Dim fileName As String = StudentID + "≈" + "S" + "≈" + Path.GetFileName(CType(item.FindControl("FileUpload2"), FileUpload).PostedFile.FileName).ToString
CType(item.FindControl("FileUpload2"), FileUpload).PostedFile.SaveAs((Server.MapPath("~/photos/Sign/") + fileName))
End If
End If
Next
Amit.Messagebx.Alert(Me, "Upload Successfully")
cmd.Dispose()
cmd.Connection.Close()
End Sub