How to change GridView row border style in asp.net c#

GridView row border style
GridView is an asp.net web server control that allow us to display values of a data source in a table. Each column of GridView represents a data source field and each row represents a record. GridView show data source data in its data row. We can separate data rows design by using row and alternate row style.

GridView RowStyle property allow us to set the appearance of data rows. RowStyle property have many sub properties to properly design data rows in GridView such as BorderColor, BorderWidth, BorderStyle, BackColor, ForeColor etc.

GridView RowStyle.BorderStyle property allow us to set or change the GridView data rows border style. BorderStyle property is set using one of the following BorderStyle enumeration values those are NotSet, None, Dotted, Dashed, Solid, Double, Groove, Ridge, Inset and Outset. Dotted value set a dotted line border in GridView data rows and Double value set a solid double line border.

The following asp.net c# example code demonstrate us how can we set or change data rows border style programmatically in a GridView server control.
GridViewRowBorderStyle.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        GridView1.RowStyle.BorderStyle = BorderStyle.Dashed;
    }    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>How to change GridView row border style programmatically in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">GridView Example: Change Row Border Style</h2>
        <asp:SqlDataSource 
            ID="SqlDataSource2"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select ProductID, ProductName, UnitPrice From Products"
            CancelSelectOnNullParameter="false"
            >
        </asp:SqlDataSource>
        <asp:GridView 
            ID="GridView1"
            runat="server"
            DataSourceID="SqlDataSource2"
            AllowPaging="true"
            BackColor="OrangeRed"
            ForeColor="Snow"
            BorderColor="Red"
            Font-Names="Comic Sans MS"
            AutoGenerateColumns="false"
            Width="550"
            >
            <RowStyle BorderWidth="2" BorderColor="Salmon" />
            <PagerStyle 
                BackColor="DarkSalmon" 
                ForeColor="Snow" 
                Font-Bold="true"
                Font-Size="Large"
                BorderColor="Salmon"
                Height="35"
                HorizontalAlign="Right"
                />
            <HeaderStyle 
                BackColor="SaddleBrown" 
                Font-Italic="false" 
                BorderColor="Brown"
                Height="35"
                ForeColor="Snow" 
                />
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="true" />
                <asp:BoundField DataField="Productname" HeaderText="Product Name" />
                <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
            </Columns>        
        </asp:GridView>
        <br />
        <asp:Button 
            ID="Button1" 
            runat="server"
            Text="Set Row Border Style Dashed"
            Font-Bold="true"
            Height="45"
            ForeColor="OrangeRed"
            OnClick="Button1_Click"
            />        
    </div>
    </form>
</body>
</html>
More asp.net examples