Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:-


VB
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
Posted

1 solution

You can try this, definitely you need to change conditions. You need to use the RowDataBound event of the gridview.


EX:
C#
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
//Check if it is not header or footer row
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        if(e.Row.RowIndex == 0)
             e.Row.Cells[0].BackColor = Color.Red;
        if(e.Row.RowIndex == 1)
 e.Row.Cells[0].BackColor = Color.Green;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900