如何更改特定行的gridview特定列的颜色。 [英] how to change the color of gridview specific column of specific row.

查看:79
本文介绍了如何更改特定行的gridview特定列的颜色。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我有一个gridview,它与学生唯一身份证和学生姓名绑定,带有两个文件上传按钮。和显示看起来像。



StudentID - StudentName - PhotoUpload - SignUpload

101 - Rajesh - fileuploadButton- fileuploadbutton

102 - Arun - fileuploadButton- fileuploadbutton





当我在gridview上传照片和学生的标志时将其保存在sql server 2005数据库中。以下数据保存在sql表中



StudentID - UploadType

101 - 照片
$ b $ 101 - 签到

102 - 签名



和照片保存在具有特定名称的文件夹中,如

'studentID≈P≈PhotoName' ex- '101≈P≈rajeshphoto'。和Sign一样

'studentID≈S≈PhotoName' ex- '101≈P≈rajeshSign'



现在,当我绑定gridview时,我需要它。那么thos文件上传按钮列的颜色是更改的,保存在数据库中。这意味着如果保存'rajesh''照片'那么photoUpload COlumn的fileupload按钮的颜色将会改变。





我的代码如下: -





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

推荐答案

你可以试试这个,绝对需要改变条件。你需要使用gridview的RowDataBound事件。





EX:

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


EX:
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;
    }
}


这篇关于如何更改特定行的gridview特定列的颜色。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆