Solved

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

Posted on 2006-06-17
14
388 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

731 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