GridView. Is this possible? RRS feed

  • Question

  • User1608082067 posted


    I have a GridView and I am using CSS Friendly Adapters. The GridView has 4 columns.

    I need to make the GridView a fixed width.

    3 columns must have the width necessary just to show their contents and the other one should fill the rest of the space.

    How can I do this with the CSS Files?

    Do I need to use Inline styling? And can I do that when I use CSS Friendly Adapters?




    Tuesday, November 13, 2007 5:30 PM


  • User601024962 posted


    U can do it as follow

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
                word-break: break-all;
                width: 40px;
                word-break: break-all;
                width: 80px;
        <form id="form1" runat="server">
                <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"

    *********** code behind
            DataTable myTable;
            protected void Page_Load(object sender, EventArgs e)
                myTable = new DataTable();
                myTable.Columns.Add("ID", typeof(Int32));
                myTable.Columns.Add("Name", typeof(String));
                myTable.Columns.Add("Job", typeof(String));
                myTable.Rows.Add(1, "aaa","test");
                myTable.Rows.Add(2, "bbbbbbbbbbbbbbbbbbbb","testtest");
                myTable.Rows.Add(3, "ccc","testtesttesteetststetstest");
                GridView1.DataSource = myTable;

            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                e.Row.Cells[1].CssClass = "column1";
                e.Row.Cells[2].CssClass = "column2";


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2007 6:20 AM