GridView添加横向滚动条

来源:互联网 发布:sql server 2017 编辑:程序博客网 时间:2024/05/17 04:08

使用div,前台代码:

<div style="overflow: auto; width: 100%">
            <%--<asp:Panel ID="Panel1" ScrollBars="Auto" runat="server" HorizontalAlign="Center">--%>
            <asp:GridView ID="GV_show" runat="server" AutoGenerateColumns="False" DataKeyNames="F_Code"
                HorizontalAlign="Center" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
                BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" OnRowDataBound="GV_show_RowDataBound"
                OnRowEditing="GV_show_RowEditing" 
                OnRowCreated="GV_show_RowCreated">



后台添加OnRowCreated函数,禁止换行操作,如下:

protected void GV_show_RowCreated(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
            e.Row.Cells[i].Wrap = false;
            e.Row.Cells[i].Attributes.Add("style", "word-break :keep-all ; word-wrap:keep-all");
        }
    }


实现效果