冻结最后几行,前几列和网格View的标题

时间:2012-12-04 10:34:30

标签: c# gridview

请建议任何解决方法来冻结我的网格视图的最后4行。

我已成功冻结标题行并留下2列。根据要求,我还需要冻结最后4行。

冻结最后4行网格视图

3 个答案:

答案 0 :(得分:0)

CSS

.frozenFooter
{
    font-weight:bold;
    background-color: Green;
    color: Black;
    position: relative;
    bottom:expression(getScrollBottom(this.parentNode.parentNode.parentNode.parentNode));
}

.frozenCell  {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: Gray;
color:Black ;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*IE5+ only*/
/*left: expression(document.getElementById("div-datagrid").scrollLeft-2);*/
/*left:expression((this.parentElement.parentElement.parentElement.parentElement.scrollLeft-2)+'px');*/

left: expression(document.getElementById("pnlContainer").scrollLeft-2);
}
.lockedForLastRow  {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: Gray;
color:Black ;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*IE5+ only*/
/*left: expression(document.getElementById("div-datagrid").scrollLeft-2);*/
/*left:expression((this.parentElement.parentElement.parentElement.parentElement.scrollLeft-2)+'px');*/

left: expression(document.getElementById("pnlContainer").scrollLeft-2);
}
.frozenHeader
{
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    background-color: Green;
    color:Black ;
    border-right: 1px solid black;
    position:relative;
    cursor: default;
    top: expression(document.getElementById("pnlContainer").scrollTop-2);
    z-index : 10;
}

</style>

脚本

             function getScrollBottom(p_oElem)         {          return p_oElem.scrollHeight - p_oElem.scrollTop - p_oElem.clientHeight;         }

HTML

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
        Width="96%"  ShowFooter="false" onrowdatabound="GridView1_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="C1">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("C1") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C1 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C2">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("C2") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C2 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C3">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("C3") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C3 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C4">
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("C4") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C4 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C5">
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("C5") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C5 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C6">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("C6") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C6 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C7">
            <ItemTemplate>
                <asp:Label ID="Label7" runat="server" Text='<%# Bind("C7") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C7 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C8">
            <ItemTemplate>
                <asp:Label ID="Label8" runat="server" Text='<%# Bind("C8") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C8 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C9">
            <ItemTemplate>
                <asp:Label ID="Label9" runat="server" Text='<%# Bind("C9") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C9 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="C10">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("C10") %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                C10 Footer Here
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>

    </asp:GridView>

</asp:Panel>

答案 1 :(得分:0)

protected void Page_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("C1");
    dt.Columns.Add("C2");
    dt.Columns.Add("C3");
    dt.Columns.Add("C4");
    dt.Columns.Add("C5");
    dt.Columns.Add("C6");
    dt.Columns.Add("C7");
    dt.Columns.Add("C8");
    dt.Columns.Add("C9");
    dt.Columns.Add("C10");
    DataRow drRow;
    for (int i = 0; i < 10; i++)
    {
        drRow = dt.NewRow();
        drRow[0] = "C10000000" + i;
        drRow[1] = "C20000000" + i;
        drRow[2] = "C30000000" + i;
        drRow[3] = "C40000000" + i;
        drRow[4] = "C50000000" + i;
        drRow[5] = "C60000000" + i;
        drRow[6] = "C70000000" + i;
        drRow[7] = "C80000000" + i;
        drRow[8] = "C90000000" + i;
        drRow[9] = "C100000000" + i;
        dt.Rows.Add(drRow);
    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
    GridView1.Rows[9].Cells[0].ID = "footerCell";
    GridView1.Rows[9].Attributes.Add("class", "frozenFooter");
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].CssClass = "frozenCell";
}

答案 2 :(得分:0)

另一个Css仅适用于作为页脚冻结的最后一行的第一个单元格(左侧滚动冻结)

.GVFixedFooterFirstCell
{ 
    font-weight:bold; 
    background-color: Green; 
    color: Black;
    position: relative;
    bottom: expression(document.getElementById("pnlContainer").scrollHeight - document.getElementById("pnlContainer").scrollTop - document.getElementById("pnlContainer").clientHeight);
    left: expression(document.getElementById("pnlContainer").scrollLeft-2);
    z-index:10;
}