?
Solved

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

Posted on 2006-06-17
14
Medium Priority
?
416 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Expert Comment

by:Sammy Ageil
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 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

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