locked
Gridview Column Width CSS RRS feed

Answers

  • User487807879 posted

    Try with this:

    white-space: nowrap;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 24, 2017 1:18 PM
  • User-1838255255 posted

    Hi KALYANA ALLAM,

    According to your description, i think you want to make all content in single line, don't want to break line, you could use white-space : nowrap or fixed width to solve the problem. Here is the sample code, please check: 

    Sample Code: 

    <head runat="server">
        <title></title>
        <style>
            .nowrap {
                white-space: nowrap;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
                runat="server" AutoGenerateColumns="false" HeaderStyle-CssClass="nowrap">
                <Columns>
                    <asp:BoundField DataField="Location" HeaderText="Location" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Facility Log Number" HeaderText="Facility Log Number" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Date of Incident" HeaderText="Date of Incident" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Incident Type" HeaderText="Incident Type" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="IRMA Incident ID" HeaderText="IRMA Incident ID" ItemStyle-CssClass="nowrap" />
                </Columns>
            </asp:GridView>
        </form>
    </body>
    
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Location", typeof(string)),
                                new DataColumn("Facility Log Number", typeof(string)),
                                new DataColumn("Date of Incident",typeof(string)),
                                new DataColumn("Incident Type",typeof(string)),
                                new DataColumn("IRMA Incident ID",typeof(string))
                    });
                    dt.Rows.Add("225 East 106th Street Apt. # 1F, New York, NY 10029 - 31640", "ABCDE", "10/12/2017", "Deliberate Inappropriate Use of Restraints - Non-XXXX EEEEEEEEEe", "n/a");
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }

    Result:

    if my understanding is wrong, please correct me! 

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 25, 2017 3:30 AM

All replies

  • User487807879 posted

    Try with this:

    white-space: nowrap;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 24, 2017 1:18 PM
  • User-1838255255 posted

    Hi KALYANA ALLAM,

    According to your description, i think you want to make all content in single line, don't want to break line, you could use white-space : nowrap or fixed width to solve the problem. Here is the sample code, please check: 

    Sample Code: 

    <head runat="server">
        <title></title>
        <style>
            .nowrap {
                white-space: nowrap;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
                runat="server" AutoGenerateColumns="false" HeaderStyle-CssClass="nowrap">
                <Columns>
                    <asp:BoundField DataField="Location" HeaderText="Location" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Facility Log Number" HeaderText="Facility Log Number" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Date of Incident" HeaderText="Date of Incident" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="Incident Type" HeaderText="Incident Type" ItemStyle-CssClass="nowrap" />
                    <asp:BoundField DataField="IRMA Incident ID" HeaderText="IRMA Incident ID" ItemStyle-CssClass="nowrap" />
                </Columns>
            </asp:GridView>
        </form>
    </body>
    
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Location", typeof(string)),
                                new DataColumn("Facility Log Number", typeof(string)),
                                new DataColumn("Date of Incident",typeof(string)),
                                new DataColumn("Incident Type",typeof(string)),
                                new DataColumn("IRMA Incident ID",typeof(string))
                    });
                    dt.Rows.Add("225 East 106th Street Apt. # 1F, New York, NY 10029 - 31640", "ABCDE", "10/12/2017", "Deliberate Inappropriate Use of Restraints - Non-XXXX EEEEEEEEEe", "n/a");
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }

    Result:

    if my understanding is wrong, please correct me! 

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 25, 2017 3:30 AM
  • User1203305613 posted

    Thanks Eric that helps

    Wednesday, October 25, 2017 5:55 PM