简体   繁体   English

临时存储数据列表c#

[英]Temporary Storage Datalist c#

So I have this problem with storing temporary data, basically the effect I'm after is something like this Link 所以我在存储临时数据时遇到了这个问题,基本上我想要的效果是这样的链接

My problem is when I do it on List or Binding list, it won't save the old rows and just change it to the new ones. 我的问题是,当我在“列表”或“绑定”列表上进行操作时,它不会保存旧的行,而只是将其更改为新的行。

Here is the code I got 这是我得到的代码

BindingList<Genrer> Film_Genrer = new BindingList<Genrer>(); 
Genrer genrer = new Genrer();
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DropDownList_Genrer.DataSource = Db.SelectAllFrom("Genrer");
        DropDownList_Genrer.DataTextField = "genrer_navn";
        DropDownList_Genrer.DataValueField = "genrer_id";
        DropDownList_Genrer.DataBind();
    }
}

protected void Button_AddGenrer_Click(object sender, EventArgs e)
{
    Genrer genrer = new Genrer();
    genrer.Navn = DropDownList_Genrer.SelectedValue;

    Film_Genrer.Add(genrer);
    GridView1.DataSource = Film_Genrer;
    GridView1.DataBind();
}

In the Button_AddGenrer_Click method, your Film_Genrer is initially empty and you just add one item to that and set it as DataSource. Button_AddGenrer_Click方法中, Film_Genrer最初是空的,您只需向其中添加一项并将其设置为DataSource。 What you need to do is first add all your items to Film_Genrer , then add the new item and then set the DataSource. 您需要做的是首先将所有项目添加到Film_Genrer ,然后添加新项目,然后设置数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM