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

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

VB
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
 
Share this answer
 
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?
 
Share this answer
 
Hi

i have searched again and this is some code that is working slighlty
VB
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

    If (e.Row.RowType = DataControlRowType.DataRow) Then
        lblgrid = e.Row.FindControl("lblsiteUPRN")
        lblgrid.Text = "X"
        If lblgrid.Text Is vbNullString Then

        End If


    End If

End Sub


this created a new column call siteUPRN and puts an x when it is blank in siteUPRN however, i do not want to create another column, i need the orginal siteUPRN (that is autogenerated from the spreadsheet) to be the one that is searched for a null value and an x (or colour change) put in the empty cell
 
Share this answer
 
hi
i lost my login details for this post so i have had to re do everythin

this is now SOLVED as i have found out how to do it

cheers for you help everyone :-)
 
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