如何从多个网页中存储来自多个gridview数据表的数据 [英] How to store data from multiple gridview datatable from multiple web pages

查看:67
本文介绍了如何从多个网页中存储来自多个gridview数据表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

所以只是想知道。我有几个页面,每个页面都有一个gridview(让我们称之为sourcegridview)。所以在这些sourcegridview中,我为每一行添加了一列复选框。每次我选中一个复选框时,该特定行将被添加到另一个gridview(我们称之为gridview CompiledGridview)。我通过将选中的行传输到数据表并将其与CompiledGridview绑定来完成此操作。所以我的问题是,如何维护添加到CompiledGridview的数据?因为我必须导航到我的每个网页并选择我想要添加到CompiledGridview的记录,并且每次我导航到不同的网页时,CompiledGridview中的数据都将消失。其中一种方式是Session但是如何绑定它?因为我有多个sourcegridview。



非常感谢任何帮助! :)

Hi guys,
So just wondering. I got a few pages where by each pages have a gridview(lets called this sourcegridview). So in these sourcegridview, I have put a column of checkboxes for each row. Every time I checked a checkbox, that particular row will be added to another gridview(lets called this gridview CompiledGridview). I did this by transferring the checked row into a datatable and bind it with the CompiledGridview. So my question is, how to maintain the data added to the CompiledGridview? Because I have to navigate to each of my webpages and select the record that I want to be added to the CompiledGridview and everytime I navigate to a different web page, the data in the CompiledGridview is gone. One of the way is Session but how to bind it? because I have multiple sourcegridview.

Any help is greatly appreciated! :)

推荐答案

如你所说,如果你想在会话中存储它,你可以创建一个这样的类:

As you said, if you want to store it at session, you can create a class like this:
public class Class1
{
    public static DataTable TableSession
    {
        get
        {
            if (HttpContext.Current.Session["dt"] == null)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("checked");
                dt.Columns.Add("name");
                HttpContext.Current.Session["dt"] = dt;
            }
            return (DataTable)HttpContext.Current.Session["dt"];
        }
        set
        {
            HttpContext.Current.Session["dt"] = value;
        }
    }
}



并可以像这样访问它:


and access it anywhere like this:

protected void Page_Load(object sender, EventArgs e)
{
    sourcegridview.DataSource = Class1.TableSession;
    sourcegridview.DataBind();

    Class1.TableSession.Rows.Add("1", "new data");

    CompiledGridview.DataSource = Class1.TableSession;
    CompiledGridview.DataBind();
}


这篇关于如何从多个网页中存储来自多个gridview数据表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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