Set GridView Width using Bootstrap and CSS in ASP.Net

on Sep 17, 2021 10:57 PM

I want to make the GridView in web forms little bit wider using bootstrap style sheets.

When I increased the width of GridView to 100% then I don’t see any change in the width of the GridView.

I also tried to put w-100, but that also didn’t make much difference.

Below is my GridView.

<div class="row justify-content-center">
    <asp:GridView ID="grdCalculate" runat="server" GridLines="Horizontal"   
        CssClass="table w-100  table-responsive-xl" OnRowDataBound="grdCalculate_RowDataBound"    >

When I put the wrapper of table responsiveness I get the border for the full width of the table, but the actual grid is squished in the corner of the table outline.

I just want to center the table and make the table slightly smaller than the outline.

any help will be highly appreciated.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Sep 18, 2021 03:50 AM

Refer below code.


<link rel="stylesheet" href=""
    integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous" />
<script type="text/javascript" src=""
    integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script type="text/javascript" src=""
    integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script type="text/javascript" src=""
    integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
<style type="text/css">
    .table-responsive {
        display: inline-table !important;
<div class="container">
    <div class="row justify-content-center">
        <div class="col-sm-6">
            <asp:GridView ID="grdCalculate" runat="server" GridLines="Horizontal"
                CssClass="table table-responsive" Width="100%">


protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[] { new DataColumn("Calculation"), new DataColumn("Value") });
        dt.Rows.Add("Test 1", 1235);
        dt.Rows.Add("Test 2", 66666);
        dt.Rows.Add("Test 3", 9999);
        dt.Rows.Add("Test 4", 666555);
        grdTest.DataSource = dt;

        grdCalculate.DataSource = dt;