Solved

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

Posted on 2006-06-17
14
363 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
Comment Utility
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
Comment Utility
didnt work for me, i dont know y
0
 

Author Comment

by:joshuadavidlee
Comment Utility
are u seeing the row lines change colouyr yourself? u have it working?
0
 
LVL 27

Expert Comment

by:Sammy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
put this in your <head> section

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

Author Comment

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

Expert Comment

by:deanvanrooyen
Comment Utility
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
Comment Utility
how would i get just horizontal lines and not vertical?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
       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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on 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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

18 Experts available now in Live!

Get 1:1 Help Now