Solved

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

Posted on 2006-06-17
14
367 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
Json and asp.net mvc 2 45
Syntax error 9 45
How to hyperlink e.Rows.Cells[1].Text before it is displayed in the GridView control. 6 15
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now