2017-07-09 30 views
0

我有一個文本框txtId和一個網格視圖,網格視圖根據ID提供的數據顯示。它是好的,但每當我第二次提供Id網格加載新數據和我以前的ID數據已從gidview中刪除。如何從數據表中加載gridview而不替換以前的數據

我想是這樣的:

enter image description here

每當我進入之前的數據已經一去不復返了我要與以前的類似上面的圖片新的數據Idsecond時間。

下面是我的網格視圖,我已經使用EVAL綁定網格:

<asp:GridView ID="GVProduct" CssClass="table table-hover" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="None" AllowPaging="True"> 
     <AlternatingRowStyle BackColor="#CCCCCC" /> 
     <Columns> 
       <asp:TemplateField HeaderText="Product Name"> 
       <ItemTemplate> 
        <asp:Label ID="lblProductName" runat="server" Text='<%#Eval("ItemName") %>' ></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="CP"> 
       <ItemTemplate> 
        <asp:Label ID="lblCP" runat="server" Text='<%#Eval("CostPrice") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
</asp:GridView> 

而且我這是怎麼加載網格上按一下按鈕:

protected void btnAdd_Click(object sender, EventArgs e) 
     { 
      int itemIds = Convert.ToInt32(txtPId.Text); 
      int qty = Convert.ToInt32(txtQty.Text); 
      if (txtPId.Text!=String.Empty || txtQty.Text != String.Empty) 
      { 
       DataTable dt = bllProduct.GetProductById(itemIds); 
       if (dt.Rows.Count>0) 
       { 
        GVProduct.DataSource = dt; 
        GVProduct.DataBind(); 
       } 
      } 
     } 

回答

0

我覺得GetProductById(itemIds)是隻返回一個記錄請在GetProductById方法中檢查您的選擇查詢。

相關問題