Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将表属性应用于具有固定页眉和页脚的asp.net GridView_Html_Css_Asp.net_Gridview_Css Tables - Fatal编程技术网

Html 将表属性应用于具有固定页眉和页脚的asp.net GridView

Html 将表属性应用于具有固定页眉和页脚的asp.net GridView,html,css,asp.net,gridview,css-tables,Html,Css,Asp.net,Gridview,Css Tables,如何将此表CSS应用于我的Gridview,因为我需要与此链接相同的网格。当我复制这个CSS并添加类名时,它不能正常工作,我只得到滚动条,但缺少固定的页眉和页脚。如何在GridView中完整地使用CSS并将其设置为CSS,以及如何为页脚设置CSS <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &

如何将此表CSS应用于我的Gridview,因为我需要与此链接相同的网格。当我复制这个CSS并添加类名时,它不能正常工作,我只得到滚动条,但缺少固定的页眉和页脚。如何在GridView中完整地使用CSS并将其设置为CSS,以及如何为页脚设置CSS

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        .wrapper {
            width: 90%;
            position: relative;
            border: 1px solid #000;
            background: #efefef;
            overflow: hidden;
            border-radius: 7px;
        }

        .containerGrid {
            overflow-y: scroll;
            height: 400px;
            border-top: 4px solid transparent;
            border-bottom: 4px solid transparent;
        }

        table {
            border-spacing: 0;
            border-collapse: collapse;
            width: 100%;
        }

        td + td {
            border-left: 1px solid #fff;
        }

        td, th {
            border-bottom: 1px solid #fff;
            background: #ff6a00;
            padding: 5px;
        }

        input[type="text"] {
            width: 100%;
            box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
        }

        .thead tr th,
        .tfoot tr td {
            height: 0;
            line-height: 0;
            margin: 0;
            padding-top: 0;
            padding-bottom: 0;
            border: none;
            white-space: nowrap;
        }

        tbody tr th {
            background-color: snow;
        }

        .thead tr th,
        .tfoot td {
            position: absolute;
            color: #000000;
            padding: 10px;
            margin-left: -10px;
            line-height: normal;
            width: 100%;
            z-index: 2;
            text-align: left;
            font-weight: bold;
        }
    </style>

</head>
<body>
    <form id="form1" runat="server">
        <div class="wrapper">
            <div class="containerGrid">
                <asp:GridView ID="Gridview2" runat="server" ShowFooter="true"
                    AutoGenerateColumns="false">
                    <HeaderStyle CssClass="thead" />
                    <FooterStyle CssClass="tfoot" />
                    <Columns>
                        <asp:TemplateField HeaderText="Ministry">
                            <ItemTemplate>
                                <asp:Label ID="Ministry" runat="server" Text='<%#Eval("Ministry")%>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtMinistry" runat="server" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Title">
                            <ItemTemplate>
                                <asp:Label ID="Title" runat="server" Text='<%#Eval("Title")%>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtTitle" runat="server" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Criteria">
                            <ItemTemplate>
                                <asp:Label ID="Criteria" runat="server" Text='<%#Eval("Criteria")%>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtTitle" runat="server" />
                            </FooterTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </div>
    </form>
</body>
</html>

.包装纸{
宽度:90%;
位置:相对位置;
边框:1px实心#000;
背景:#efef;
溢出:隐藏;
边界半径:7px;
}
乌贼{
溢出y:滚动;
高度:400px;
边框顶部:4倍实心透明;
边框底部:4px实心透明;
}
桌子{
边界间距:0;
边界塌陷:塌陷;
宽度:100%;
}
td+td{
左边框:1px实心#fff;
}
td,th{
边框底部:1px实心#fff;
背景:#ff6a00;
填充物:5px;
}
输入[type=“text”]{
宽度:100%;
框大小:边框框;
-webkit框大小:边框框;
-moz框大小:边框框;
}
thead tr th,
.tfoot tr td{
身高:0;
线高:0;
保证金:0;
填充顶部:0;
填充底部:0;
边界:无;
空白:nowrap;
}
t车身变速器{
背景颜色:雪;
}
thead tr th,
.tfoot td{
位置:绝对位置;
颜色:#000000;
填充:10px;
左边距:-10px;
线高:正常;
宽度:100%;
z指数:2;
文本对齐:左对齐;
字体大小:粗体;
}
代码隐藏:

   protected void Page_Load(object sender, EventArgs e)
        {
            var obj = new { Ministry = "Ministry 0", Title = "Title 0", Criteria = "Criteria 0" };
            var objList = (new[] { obj }).ToList();
            for (int i = 1; i < 30; i++)
            {
                objList.Add(new { Ministry = "Ministry " + i.ToString(), Title = "Title " + i.ToString(), Criteria = "Criteria " + i.ToString() });
            }
            Gridview2.DataSource = objList;
            Gridview2.DataBind();
        }
受保护的无效页面加载(对象发送方,事件参数e)
{
var obj=新的{Ministry=“Ministry 0”,Title=“Title 0”,Criteria=“Criteria 0”};
var objList=(new[]{obj}).ToList();
对于(int i=1;i<30;i++)
{
objList.Add(新的{Ministry=“Ministry”+i.ToString(),Title=“Title”+i.ToString(),Criteria=“Criteria”+i.ToString()});
}
Gridview2.DataSource=objList;
Gridview2.DataBind();
}

首先添加下面的代码。默认情况下,GridView不会生成
元素。所以你的CSS不能正常工作

<asp:GridView ID="Gridview2" runat="server" OnRowDataBound="GridView2_RowDataBound">

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.TableSection = TableRowSection.TableHeader;
    }
}

受保护的void GridView2_RowDataBound(对象发送方,GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.Header)
{
e、 Row.TableSection=TableRowSection.TableHeader;
}
}

感谢您的回答,这是您刚才说的,但CSS的应用与链接上的应用不同,您是否有其他解决方案或示例来说明如何在gridview上修复页眉和页脚并添加滚动?