清理后无法添加gridview

时间:2015-11-19 13:44:38

标签: c# asp.net gridview add clear

我正在使用实体框架并从数据库中获取我的数据并用它们填充我的gridview。用户从treview中选择数据。简单地说,用户从树视图中选择数据并将其放入gridview。最后,我有一个用于清除gridview的按钮。这是我的aspx:

<div id="divPrint" style="background-color: white" runat="server">
   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <ContentTemplate>
       <p style="text-align:center">HDCVI KAMERA FİYAT TEKLİFİDİR</p>
         <asp:GridView ID="GridViewHdcvi" runat="server" DataSourceID="EntityDataSourceHdcvi" AutoGenerateColumns="False">
          <Columns>
          <asp:TemplateField HeaderText="ÜRÜN VE DETAYLARI">
          <ItemStyle Width="400px" />
          <ItemTemplate>
          <div style="color: red" class="text-center"><%#Eval("UrunAdi") %></div>
          <%#Eval("UrunDetay") %>
          </ItemTemplate>
          </asp:TemplateField>
          <asp:ImageField HeaderText="ÜRÜN GÖRSELİ" DataImageUrlField="UrunResim"></asp:ImageField>
           <asp:TemplateField HeaderText="BİRİM FİYAT">
           <ItemTemplate>
           <%#Eval("UrunFiyati") %>
            </ItemTemplate>
            </asp:TemplateField>
           <asp:TemplateField HeaderText="ADET">
              <ItemTemplate>
    <asp:TextBox ID="txtAdet" runat="server" Width="40px"></asp:TextBox>
           </ItemTemplate>
          </asp:TemplateField>
           </Columns>
          </asp:GridView>
          </ContentTemplate>
           </asp:UpdatePanel>
         </div>
<asp:Button ID="btnListiSifirla" runat="server" Text="Listeyi Sıfırla" CssClass="btn btn-danger" OnClick="btnListiSifirla_Click" />

我的代码隐藏:

 static List<string> urunList = new List<string>();

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        string id = TreeView1.SelectedValue;
        urunList.Add(id); 
        listeyiDoldur();
    }

    protected void listeyiDoldur() 
    {
        if (urunList.Count == 0)
        {
            failDiv.Visible = true;
        }
        else
        {
            string query = "SELECT UrunTable.UrunAdi, UrunTable.UrunFiyati, UrunTable.UrunResim, UrunTable.UrunKategori, UrunTable.UrunDetay FROM UrunTable WHERE ";
            foreach (var val in urunList)
            {
                if (val.Equals(urunList[urunList.Count - 1]))
                {
                    query += "UrunTable.UrunId = " + val;
                }
                else
                {
                    query += "UrunTable.UrunId = " + val + " || ";
                }
            }
            EntityDataSourceHdcvi.CommandText = query;
            divPrint.Visible = true;
            btnListiSifirla.Visible = true;
        }
    }

    protected void btnListiSifirla_Click(object sender, EventArgs e)
    {
        urunList.Clear();
        btnListiSifirla.Visible = false;
        Page_Load(null,EventArgs.Empty);
    }

我可以在gridview中成功显示所选数据,并在按下按钮时将其清除。这是问题:清除gridview后我无法再添加最后添加的项目。例如,如果我按此顺序添加item1,item2和item3,清除gridview后我无法添加item3。我可以添加item1或item2,然后添加item3。我不能首先添加项目,我在清理之前添加了最后一项。我尝试在按钮的onClick中清除gridview并尝试了其他很多东西,但没有任何结果。谢谢你的时间。

0 个答案:

没有答案