2015-04-08 53 views
0

我正在使用網格視圖來顯示來自數據庫的記錄。 Gridview有分頁,pagesize設置爲15。當用戶點擊此鏈接時,其中一列具有鏈接字段,它將繼續執行某些功能。那麼什麼是我的問題是刪除在gridview底部自動添加gridview的空行

  • 1)當小於頁面大小的記錄號的最後一頁是 縮水。這對我來說是k。但點擊網格視圖鏈接時會自動添加 空行。我如何刪除這些空行?

  • 2)上點擊視圖鏈接頁索引變爲1例如我在 3頁網格視圖和點擊第三頁的頁索引號碼 改變爲1,但視圖鏈接的頁面顯示第三行記錄。我該如何修復 這個..?

請任何能幫助我..謝謝提前

網格視圖代碼: -

<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)); 
      } 
     } 
+0

我有編輯我的代碼示例 –

+0

在後面的代碼,我只是將數據綁定問題源到gridview –

+0

那麼你在做什麼'OnPageIndexChanging =「gvGRNListAll_PageIndexChanging」'。同時顯示綁定代碼。 – BNN

回答

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; 
} 

希望它可以幫助

+0

我試過上面的代碼。但不起作用 –

+0

您需要在gridview中從count'0'開始正確設置'Cells []',並在要刪除的列上添加單元格no – BNN