Grid Line Color

Discussion in 'ASP .Net Datagrid Control' started by Brett Robichaud, Apr 1, 2004.

  1. How does one change the color of the lines between items in a datagrid?

    I've played with every css style I can find and nothing works.

    -Brett-
    Brett Robichaud, Apr 1, 2004
    #1
    1. Advertising

  2. Hi Brett,

    Based on my understanding, you want to change the lines color in the
    datagrid control.

    Actually, in asp.net, webform datagrid control will render as <table> html
    element in client.

    For example, if you use Sql Server's default datatable "jobs" to bind the
    DataGrid like this:

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlDataAdapter adapter=new SqlDataAdapter("select * from jobs",
    "server=localhost; database=pubs;uid=sa;pwd=");
    DataSet ds=new DataSet();
    adapter.Fill(ds);
    DataGrid1.DataSource=ds;
    DataGrid1.DataBind();
    }

    At client, it will render something like this:

    <table cellspacing="0" rules="all" border="1" id="DataGrid1"
    style="height:192px;width:352px;border-collapse:collapse;Z-INDEX: 101;
    LEFT: 48px; POSITION: absolute; TOP: 48px">
    <tr>
    <td>job_id</td><td>job_desc</td><td>max_lvl</td><td>enum</td>
    </tr>
    ........
    </table>

    You can see that, the grid lines in the DataGrid are actually the borders
    of <td> elements in <table> and <tr>, it default color is black. If you
    want to give a different color to it, you should apply bordercolor
    attribute to the entire <table>. In asp.net server side, you may use
    DataGrid.Attributes.Add method to add the attribute. Do like this:

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlDataAdapter adapter=new SqlDataAdapter("select * from jobs",
    "server=localhost; database=pubs;uid=sa;pwd=");
    DataSet ds=new DataSet();
    adapter.Fill(ds);
    DataGrid1.DataSource=ds;
    DataGrid1.DataBind();
    this.DataGrid1.Attributes.Add("bordercolor","red");
    }

    This will render as:

    <table cellspacing="0" bordercolor="red" rules="all" border="1"
    id="DataGrid1"
    style="height:192px;width:352px;border-collapse:collapse;Z-INDEX: 101;
    LEFT: 48px; POSITION: absolute; TOP: 48px">
    <tr>
    <td>job_id</td><td>job_desc</td><td>max_lvl</td><td>enum</td>
    </tr>
    ........
    </table>

    Then you will get a red grid line DataGrid control.

    ==============================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Apr 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo
    Replies:
    10
    Views:
    1,288
    Matt Humphrey
    Oct 18, 2004
  2. kaushikshome
    Replies:
    4
    Views:
    743
    kaushikshome
    Sep 10, 2006
  3. scad
    Replies:
    23
    Views:
    1,128
    Alf P. Steinbach
    May 17, 2009
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    364
    Kamaljeet Saini
    Feb 13, 2009
  5. Marek Stepanek
    Replies:
    12
    Views:
    395
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page