更改GridView上的单元格颜色 [英] changing cell colour of on a gridview

查看:87
本文介绍了更改GridView上的单元格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用VS2010,并且创建了一个页面,当用户单击按钮时,该页面将允许他们查看要上传到sql服务器的电子表格.基本上,这只是允许他们检查格式是否正确以及是否填充了所有单元格.网格信息显示在gridview中.但是我要更改的是空白/不包含任何信息的特定单元格的单元格背景色,因此用户可以看到缺少信息.

有人可以帮忙吗

谢谢:-)

解决方案

我不确定,但是下面的代码可能会有所帮助:-

 受保护的  GridView1_RowDataBound( ByVal 发​​件人 As  对象 ByVal  e  As  GridViewRowEventArgs)
    如果 e.Row.RowType = DataControlRowType.DataRow 然后
         Dim  col  As  整数 =  0 
        同时 col< GridView1.Columns.Count
             Dim 行值 As  字符串 = e.Row .Cells(col).文本
            如果 rowvalue = "  然后
                e.Row.Cells(col).BackColor = System.Drawing.Color.Red
            其他
                e.Row.Cells(col).BackColor = System.Drawing.Color.White
            结束 如果
            col + =  1 
        结束 同时
    结束 如果
结束  



让我知道它是否有效

-
AJ


这应该可以帮助您:

http: //stackoverflow.com/questions/3146456/how-can-i-change-the-background-color-of-gridview-cell-on-on-a-conditional [ http://www.dotnetspark.com/Forum/253-change- background-color-cell-gridview-programatically.aspx [ ^ ]


否:-(它们都不起作用.

在将电子表格导入到sql serv中之前,我用来查看电子表格的代码如下
受保护的Sub ButtonView_Click(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理ButtonView.Click
PanelUpload.Visible = False
PanelView.Visible = True
PanelImport.Visible = False

将objDataAdapter变暗为新的OleDbDataAdapter()

objDataAdapter.SelectCommand = ExcelConnection()

将objDataSet设置为新的DataSet()

objDataAdapter.Fill(objDataSet)


GridView1.DataSource = objDataSet.Tables(0).DefaultView
GridView1.DataBind()
结束子


因此,当用户单击此视图按钮时,他们将看到显示在gridview中的电子表格.但是电子表格中有些单元格为空,因此我需要在gridview中将这些单元格更改为RED :-(

有可能吗?


hi
i am using VS2010 and i have created a page that, when the user clicks a button it will allow them to view the spreadsheet that they want to upload to an sql server. this is basically just to allow them, to check that it is in the right format and all cells are populated. the spreadhseet information is displayed in a gridview. but what i want is to change the cell background colour of a specific cell that is blank/does not contain any information, so the user can see that there is missing information.

can someone please help

thanks :-)

解决方案

I am not sure but may be the following code will help : -

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim col As Integer = 0
        While col < GridView1.Columns.Count
            Dim rowvalue As String = e.Row.Cells(col).Text
            If rowvalue = "" Then
                e.Row.Cells(col).BackColor = System.Drawing.Color.Red
            Else
                e.Row.Cells(col).BackColor = System.Drawing.Color.White
            End If
            col += 1
        End While
    End If
End Sub



Let me know if it works

--
AJ


This should help you:

http://stackoverflow.com/questions/3146456/how-can-i-change-the-background-color-of-a-gridview-cell-based-on-a-conditional[^]

http://www.dotnetspark.com/Forum/253-change-background-color-cell-gridview-programatically.aspx[^]


no :-( none of them worked.

the code that i am using to view the spreadsheet before it is imported into the sql serv is as follows
Protected Sub ButtonView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonView.Click
PanelUpload.Visible = False
PanelView.Visible = True
PanelImport.Visible = False

Dim objDataAdapter As New OleDbDataAdapter()

objDataAdapter.SelectCommand = ExcelConnection()

Dim objDataSet As New DataSet()

objDataAdapter.Fill(objDataSet)


GridView1.DataSource = objDataSet.Tables(0).DefaultView
GridView1.DataBind()
End Sub


so when the user clicks this view button they will see the spreadsheet displayed in the gridview. but there are some cells in the spreadsheet that are empty and i need these cells to be changed to RED in the gridview :-(

is it possible?


这篇关于更改GridView上的单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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