All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET中实现多文件上传的实例程序代码_[Asp.Net教程]
.Net下调用SqlServer存储过程_[SQL,Server教程]
分页,SQLServer存储过程_[SQL,Server教程]
PHP技巧:何避免页面刷新数据重复写入数据库_[PHP教程]
理解学习PHP编码规范之注释和文件结构_php资料_编程技术
.NET关于同步、异步及Socket_[Asp.Net教程]
新手学习用PHP程序对网页表单的处理_php资料_编程技术
全面理解javascript的caller,callee,call,apply概念_JavaScript技术_编程技术
全面接触SQL语法(5)_mssql学习_编程技术
PHP实现gzip页面压缩方法_[PHP教程]
Reading number is top 10 pictures
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line
什么叫国家
The terra-cotta warriors1
India's national beauty of the college students
教你22句话
29 the belle stars after bath figure1
Sora aoi on twitter1
30 beautiful school beauty1
西班牙山村小景5
史上最大的哺乳动物迁移
Download software ranking
变速齿轮3.26
塘西风月痕
传奇私服架设教程
C++编程教程第三版
虚拟机汉化软件
XML+Web+Service开发教程
1400篇各类破解文章
Unix video tutorial18
Tram sex maniac 2 (H) rar bag9
Macromedia Dreamweaver 8
归海一刀 published in(发表于) 2014/1/30 1:09:34 Edit(编辑)
动态添加gridview行_[Asp.Net教程]

动态添加gridview行_[Asp.Net教程]

动态添加gridview行_[Asp.Net教程]

c#代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}


private DataTable ReadGridView()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("ProductID", typeof(string)));
dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
dt.Columns.Add(new DataColumn("CategoryID", typeof(string)));
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
dr = dt.NewRow();
dr[0] = this.GridView1.Rows[i].Cells[0].Text.Trim();
dr[1] = this.GridView1.Rows[i].Cells[1].Text.Trim();
dr[2] = this.GridView1.Rows[i].Cells[2].Text.Trim();
dt.Rows.Add(dr);
}
return dt;
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = ReadGridView();
//this.GridView1.DataSource = dt;
//this.GridView1.DataBind();
DataRow row = dt.NewRow();
row.ItemArray = new object[] { "oec2003","oec2003","oec2003" };
dt.Rows.InsertAt(row, 0);
dt.AcceptChanges();
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}


private void BindGrid()
{
string str = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString();
using (SqlConnection con = new SqlConnection(str))
{
SqlCommand cmd = new SqlCommand("SELECT top 1 [ProductID], [ProductName], [CategoryID] FROM [Products]", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
sda.Dispose();
ds.Dispose();
}


}
}


html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页





onClick="Button1_Click" Text="Button" />


ReadOnly="True" SortExpression="ProductID" />









数据库连接字串



下载:AddRow.rar


来源:http://www.cnblogs.com/oec2003







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.