asp.net网格视图问题 [英] asp.net grid view question

查看:63
本文介绍了asp.net网格视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格视图,并按数据表填充此网格视图,
但是一段时间后,我想在现有的网格视图上添加新数据
我如何在不干扰gridview的旧状态的情况下从数据表在网格视图上添加新数据
请帮助我
在此先感谢

I have a grid view and i populate this grid view by data table,
but after some time i want to add new data on the existing grid view
how i add new data on the grid view from the datatable without disturbing the old state of gridview
please help me
thanks in advance

推荐答案

只需存储您的数据表为Session变量,并将新行添加到数据表并将其作为数据源提供给您的gridview.

Just store your datatable is Session variable and add new row to datatable and give it as datasource to your gridview.

DataTable dt = null;
try
{
    if (Session["dtItems"] != null)
    {
        dt = (DataTable)Session["dtItems"];
    }
    else
    {
        dt = new DataTable();
        dt.Columns.Add("Quantity");
        dt.Columns.Add("Rate_Unit");
        dt.Columns.Add("Amount");
    }
    DataRow dataRow;
    dataRow = dt.NewRow();
    dataRow["Quantity"] = TextBox1.Text;
    dataRow["Rate_Unit"] = TextBox2.Text;
    dataRow["Amount"] = TextBox3.Text;
    dt.Rows.Add(dataRow);
    dt.AcceptChanges();
    Session["dtItems"] = dt;
    GridView1.DataSource = dt.DefaultView;
    GridView1.DataBind();
}
catch (Exception ex)
{
}


这篇关于asp.net网格视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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