将用户输入添加到列表,然后填充Gridview [英] Adding User input to List then populating Gridview

查看:52
本文介绍了将用户输入添加到列表,然后填充Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3层应用程序(DAL,BBL,UI)目前,BBL只是通行证

I have an 3 tier application (DAL, BBL, UI) BBL at the moment do Nothing just a pass-thru

我有一个网格视图,为简单起见,一个文本框(TB)和一个下拉列表(DDL).和两个提交按钮.

I have a grid view and for simplicity's sake one text box(TB) and one drop down list(DDL). and Two submit buttons.

(仅在此示例中,我将自定义类"更改为对象".)

(I changed my Custom Class to Object. just for this example)

首先提交"按钮将添加TB.DDL.SelectedValue转换为用户界面中的对象X.

First Submit button adds the TB.text & DDL.SelectedValue to a Object X in the UI.

BBL将该对象X添加到BBL中的List(X)中.

the BBL takes that object X to adds it to a List(X) in the BBL.

然后,BBL应该使用List(X)填充Gridview.(使用ajax部分页面加载)

Then the BBL should populate the Gridview with the List(X). (with ajax partial page load)

第二个Submit应该将完整的List(X)发送到数据库.

the second Submit should send the full List(X) to the database.

我遇到的问题是,当我单击第一个Submit(本地)时,我没有得到新的行,只是继续写同一行.我想念什么?

The problem im having is when I click the first Submit(the local) I dont get new Rows just keep over writing the same row. what am I Missing?

在用户界面类中

   private businesslogic blogic = new businesslogic();

   protected void B1_local_Click(object sender, EventArgs e)
    {

        object x = new object();
        x.id = Convert.ToInt32(TB_1.Text);
        x.var1 = Convert.ToInt32(DDL_1.SelectedValue);

        blogic.addrowtolist(x);

        Gridview1.DataSource = blogic.grablist();
        Gridview1.Databind();

     }

在BBL类中

    public List<object> locallist = new List<object>();
    public void addrowtolist(object x)
    {
       locallist.Add(x);

    }
    public List<object> grablist()
    {
     return locallist;
    }

推荐答案

每次回发时,您都在使用新的(空)列表加载新的BL.要查看列表的增长情况,您需要将其保存在一个请求与下一个请求之间持续存在(不会消失)的地方.

With every postback, you're loading a new BL with a new (empty) List. To see your List grow, you're going to need to save it somewhere that persists (doesn't disappear) between one request and the next.

我建议将您的列表放在会话密钥中

I would recommend putting your List in a Session key

Session["items"] = blogic.locallist;

,然后将其取出并在回发时将其发送到第二个BL构造函数.这可能是最简单的方法,但并非总是正确的方法.

and then pulling it out and sending it to a second BL constructor on postback. This is probably simplest, but not always the correct approach.

http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx

这篇关于将用户输入添加到列表,然后填充Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆