惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - yunshu

(转帖)C/S、B/S及三层结构漫谈 TP-Link 配置(转帖) 如何用VSS VS2005重置按钮代码 asp.net 2.0 网站导航控件 WEB自定义控件小记 VS2005 DataGridView 和 GirdView 横向大比拼 web.config中连接字符串与数据库登陆方式的联系 转帖-win2003各版本的区别 您没有调试该服务器的权限,验证您是服务器“Debugger Users”组的成员 错误:未将对象引用设置到对象的实例 在绑定DataGrid控件,做添加删除时遇到问题(数组越界) visual studio.net已检测到指定的web服务器运行的不是asp.net1.1版。 request('id')语句,返回的是什么类型的数据 [WebMethod] 是什么意思? 怎样添加本地web引用 创建XML文件的两种方法 枚举类型是什么意思,怎么用? 什么是DOM?
如何在DataSet中追加记录
yunshu · 2008-04-02 · via 博客园 - yunshu

在Session里缓存这个DataTable,那么可以这样做:
首先为了方便访问,可以把DataTable做成一个属性,像这样:

public DataTable objTable
{
    get
    {
        return Session["myTable"] != null ? (DataTable)Session["myTable"] : new DataTable();
    }
    set
    {
        Session["myTable"] = value;
    }
}

之后在每次点击按钮的时候,先从Session里取出来缓存的DataTable对象,再追加,最后绑定。

private void Button1_Click(object sender, System.EventArgs e)
{   
    DataTable mydt = objTable;
   
    if(mydt.Rows.Count == 0)
    {
        mydt.Columns.Add(new DataColumn("姓名"));
        mydt.Columns.Add(new DataColumn("性别"));
    }
    DataRow mydr;
    mydr = mydt.NewRow();
    mydr[0] = TextBox1.Text.ToString();
    mydr[1] = TextBox2.Text.ToString();
    mydt.Rows.Add(mydr);

    objTable = mydt;
    dg.DataSource = mydt;
    dg.DataBind();               
}