Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I make the gridview or datagrid lines a different colour?

Posted on 2006-06-17
14
377 Views
Last Modified: 2008-01-09
I hate the standard grey colour for the gridview lines between rows and columns, how do I change this?
0
Comment
Question by:joshuadavidlee
14 Comments
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16928140
here is an example. This would change the colors of the gridlines. Extract My style sttributes and try

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" BackColor="#FFC0C0" BorderColor="Black" BorderStyle="None" BorderWidth="2px" CellPadding="1" CellSpacing="1">
0
 

Author Comment

by:joshuadavidlee
ID: 16928208
didnt work for me, i dont know y
0
 

Author Comment

by:joshuadavidlee
ID: 16928313
are u seeing the row lines change colouyr yourself? u have it working?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:Sammy
ID: 16928516
use the same declaration REA_ANDREW gave you but change the BorderStyle from none to another color blue/red any color you think will show on your page.
are you using asp.net 1.1 or 2.0?

0
 

Author Comment

by:joshuadavidlee
ID: 16928519
2.0 and yesi tied it all, i have done soem more research on this, apparently other people are having the same sisue and it either works for you or it doesnt.
0
 
LVL 7

Expert Comment

by:kGenius
ID: 16928645
can you provide the code for the gridview, then we can see what's going wrong, or what's there to suggest.

Have you tried to use the "auto format" in the smart tag of your grid? Can you change colors with that?
Do you use css?

kGenius
0
 

Author Comment

by:joshuadavidlee
ID: 16928649
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                    DataKeyNames="Question_ID" DataSourceID="SqlDataSource1" OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound" CellPadding="2" Width="100%" BackColor="White" BorderColor="Red" BorderStyle="Solid" BorderWidth="2px" CellSpacing="2">
                    <Columns>
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16928683
put this in your <head> section

    <style id="test" runat=server type="text/css">
    td
     {
        border-color:Green;
     }
    </style>
0
 

Author Comment

by:joshuadavidlee
ID: 16929778
i dont have a <head> section, where would/should it be?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16930961
you should have a head section in the aspxhtml source view,

I just worked out how to do it anyways programatically -

eg if you wanted to changes the line color if the row was selected

gridview

   protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView gv = (GridView)sender;

        GridViewRow gr = gv.SelectedRow;

        foreach (TableCell cell in  gr.Cells )
        {
            cell.BackColor = System.Drawing.Color.DarkGray;
            cell.BorderStyle = BorderStyle.Solid;
            cell.BorderWidth = 3;
            cell.BorderColor = System.Drawing.Color.Blue;
        }

    }

datagrid

   protected void DataGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataGrid dg = (DataGrid)sender;

        DataGridItem dgr = dg.SelectedItem;

        foreach (TableCell cell in dgr.Cells)
        {
            cell.BackColor = System.Drawing.Color.DarkGray;
            cell.BorderStyle = BorderStyle.Solid;
            cell.BorderWidth = 3;
            cell.BorderColor = System.Drawing.Color.Blue;
        }
    }

if you want to chnage all the lines then iterate through all rows and through cells of each row....
0
 

Author Comment

by:joshuadavidlee
ID: 16930975
how would i get just horizontal lines and not vertical?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16931461
       foreach (TableCell cell in dgr.Cells)
        {
            cell.BackColor = System.Drawing.Color.DarkGray;
            cell.BorderStyle = BorderStyle.Solid;
            cell.BorderWidth = 3;
            cell.Style["border-bottom-color"] = "Blue";

        }
0
 

Author Comment

by:joshuadavidlee
ID: 16934793
ok almost there, i want just white background, and just lines, so i had to make the border colour white for the grid or your example didntlook pretty, so i also made cell.BorderWidth 1 and its almost perfect except there r tiny white dots between each cell line? no how to get rid of that? they r from the borders on the left and right of the cells
0
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 16939541
try

        DataGrid dg = (DataGrid)sender;

        DataGridItem dgr = dg.SelectedItem;

        foreach (TableCell cell in dgr.Cells)
        {
            cell.Style["background-color"] = "AliceBlue";
            cell.BorderStyle = BorderStyle.Solid;
            cell.BorderWidth = 3;
            //cell.Style["padding"] = "0px";
            cell.Style["border-color"] = "#C6D6EF";
            cell.Style["border-right-width"] = "0px";
            cell.Style["border-left-width"] = "0px";


        }

if you want the hole grid just to be lines then - dg.GridLines = GridLines.Horizontal;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question