Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using grid view to show records from database. Gridview has pagination and pagesize is set as 10. And one column has link field when user click this link it proceed some functionality. Now what is my problem is

1) when number of records less than page size the last page is shrunk. it's k for me. but on clicking view link in grid view the empty row added automatically. how do i remove these empty row?

2) on clicking view link the page index changed to 1. example i am in 3 page of grid view and clicking view link in 3rd page the page index number changed to 1 but the page shows 3rd row record. how do i fix this..?

please any can help me.. thanks in advance
<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"
    <AlternatingRowStyle BackColor="White" />
    <PagerStyle CssClass="pager" />
        <asp:TemplateField HeaderText="S.No">
                <asp:Label ID="Label1" runat="server" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
            <ItemStyle HorizontalAlign="Left" Width="10%" />
        <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 DataField="GRNDate" HeaderText="GRNDate" />
        <asp:TemplateField HeaderText="Action" SortExpression="ExId" ControlStyle-ForeColor="Blue">
                <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>
            <ControlStyle ForeColor="#FF3300" />
            <HeaderStyle CssClass="GridHeaderROW" Width="10%" />
            <ItemStyle CssClass="GridItemROW" Width="10%" />
    <EmptyDataRowStyle HorizontalAlign="Center" VerticalAlign="Bottom" ForeColor="#FF3300" />
        No Records Found.
    <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" />

viewlink click event code
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));
Updated 7-Apr-15 21:23pm
Suvendu Shekhar Giri 8-Apr-15 2:57am    
You need to share the code for the event for the view link clicked.
januskarthik 8-Apr-15 3:07am    
i have updated my code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900