locked
GridView. Is this possible? RRS feed

  • Question

  • User1608082067 posted

    Hello,

    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?

    Thanks,

    Miguel
     

      

    Tuesday, November 13, 2007 5:30 PM

Answers

  • User601024962 posted

    hi,

    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">
            .column1
            {
                word-break: break-all;
                width: 40px;
            }
            .column2
            {
                word-break: break-all;
                width: 80px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
                    Style="">
                </asp:GridView>
            </div>
        </form>
    </body>
    </html>


    *********** 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;
                GridView1.DataBind();
            }

            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