删除gridview中的空行,该行自动添加到gridview的底部

时间:2015-04-08 06:27:37

标签: asp.net gridview grid

我正在使用网格视图来显示数据库中的记录。 Gridview具有分页功能,pagesize设置为15。当用户单击此链接时,一列有链接字段,它会继续执行某些功能。现在我的问题是什么

  • 1)当最后一页的记录数小于页面大小时 压缩。这对我来说是个好消息。但是在网格视图中单击视图链接时 空行自动添加。我如何删除这些空行?

  • 2)点击查看链接时,页面索引更改为1.示例我在 网页视图的3页并在第3页的页面索引中单击视图链接 number更改为1,但页面显示第3行记录。我该如何解决? 这..?

请任何人可以帮助我..提前感谢

网格视图代码: -

<asp:GridView ID="gvGRNListAll" runat="server" AutoGenerateColumns="False" Style="width: 100%;"
    AllowPaging="True" PageSize="15" OnPageIndexChanging="gvGRNListAll_PageIndexChanging"
    CellPadding="4" ForeColor="#333333" BorderColor="#CCCCCC" ShowHeaderWhenEmpty="True"
    GridLines="None">
    <AlternatingRowStyle BackColor="White" />
    <PagerStyle CssClass="pager" />
    <Columns>
        <asp:TemplateField HeaderText="S.No">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Left" Width="10%" />
        </asp:TemplateField>
        <asp:BoundField DataField="LocationName" HeaderText="Location" />
        <asp:BoundField DataField="SupplierName" HeaderText="Supplier Name" />
        <asp:BoundField DataField="GRNNo" HeaderText="GRN No" />
        <asp:BoundField DataField="InvoiceNo" HeaderText="In.No">
            <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
        </asp:BoundField>
        <asp:BoundField DataField="GRNDate" HeaderText="GRNDate" />
        <asp:TemplateField HeaderText="Action" SortExpression="ExId" ControlStyle-ForeColor="Blue">
            <ItemTemplate>
                <asp:HiddenField ID="hdnStoreCode" runat="server" Value='<%# Eval("StoreCode") %>' />
                <asp:HiddenField ID="hdnGRNNo" runat="server" Value='<%# Eval("GRNNo") %>' />
                <asp:LinkButton ID="lbView" OnClick="lbView_Click" runat="server" Text="View"></asp:LinkButton>
            </ItemTemplate>
            <ControlStyle ForeColor="#FF3300" />
            <HeaderStyle CssClass="GridHeaderROW" Width="10%" />
            <ItemStyle CssClass="GridItemROW" Width="10%" />
        </asp:TemplateField>
    </Columns>
    <EmptyDataRowStyle HorizontalAlign="Center" VerticalAlign="Bottom" ForeColor="#FF3300" />
    <EmptyDataTemplate>
        No Records Found.
    </EmptyDataTemplate>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

PageIndexChanged

protected void gvGRNListAll_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvGRNListAll.PageIndex = e.NewPageIndex;
    SearchData();
    gvGRNListAll.PageIndex = 0;
}

Searchdata代码:

public void SearchData()
    {
       DataTable dtGRN = objBAL.FilterGRNScannedList("filterGRNScannedList", suppliercode, grnno, locationcode, Fromdate, Todate, "");
       gvGRNListAll.DataSource = dtGRN; 
       gvGRNListAll.DataBind();
    }

Onclick事件代码:

if (sender is LinkButton)
        {
            GridViewRow gvrCurrent = ((LinkButton)sender).NamingContainer as GridViewRow;
            hdnGRNNo = (HiddenField)gvrCurrent.FindControl("hdnGRNNo");
            hdnStore = (HiddenField)gvrCurrent.FindControl("hdnStoreCode");
            gvGRNListAll.Rows[gvrCurrent.RowIndex].BackColor = System.Drawing.Color.Empty;
            gvGRNListAll.Rows[gvrCurrent.RowIndex].BackColor = System.Drawing.ColorTranslator.FromHtml("#D8D8D8");
            if (hdnGRNNo != null && hdnStore != null)
            {
                GetGRNListForNo(hdnGRNNo.Value, Convert.ToInt32(hdnStore.Value));
            }
        }

1 个答案:

答案 0 :(得分:0)

RowDataBound上执行类似下面的操作

private void gvGRNListAll_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.Cells[6].Text == "")    // here add the cell no at which the row is coming blank.
    e.Row.Visible = false;
}

希望有所帮助