How to change GridView generated table style: border-collapse:collapse;.


By default, GridView generates table style with  border-collapse:collapse;. It works for most cases but sometime we need to change the border style to  border-collapse:separate;.  There is no easy way to do through style settings.

Here is a code snippet to do this through GridView’s PreRender (or Oninit/OnLoad) event to change this style. 

OnPreRender="GridView1_OnPreRender"

protected void GridView1_OnPreRender(object sender, EventArgs e)
    {
        GridView1.CellSpacing = -1;      //remove the default value
        GridView1.Style["border-collapse"] = "seperate"; //add seperate to the style
    }
 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s