使用C#向gridview添加新行 [英] add new row to gridview with C#

查看:144
本文介绍了使用C#向gridview添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,



我尝试向gridview添加新行但不成功,任何机构都可以建议我如何添加新行并将变量赋给单元格

解决方案

用户在代码下面,



DataTable dt = new DataTable();

DataRow dr = null;

dt.Columns.Add(new DataColumn(RowNumber,typeof(string)));

dt.Columns.Add( new DataColumn(Col1,typeof(string)));

dt.Columns.Add(new DataColumn(Col2,typeof(string)));

dt.Columns.Add(new DataColumn(Col3,typeof(string)));

dt.Columns.Add(new DataColumn(Col4,typeof(string)));

dt.Columns.Add(new DataColumn(Col5,typeof(string)));

dr = dt.NewRow();

dr [RowNumber] = 1;

dr [Col1] = string.Empty;

dr [Col2] = string.Empty;

dr [Col3] = string.Empty;

dr [Col4] = string.Empty;

dr [Col5] = string.Empty;

dt.Rows.Add(dr);



我认为它的工作。


参考:



http://www.aspsnippets.com/Articles/Add-new-Row-to-GridView-on-Button-Click-in-ASPNet .aspx [ ^ ]





动态添加和删除ASP.NET GridView中的行 [ ^ ]


HI,希望这个链接可以帮到你:



如何在asp.net的网格视图中插入空行 [ ^ ]

dear frinds,

I am try to add new row to gridview but not success, can any body suggest me how can add new row and assign variable to cell

解决方案

User below code,

DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Col1", typeof(string)));
dt.Columns.Add(new DataColumn("Col2", typeof(string)));
dt.Columns.Add(new DataColumn("Col3", typeof(string)));
dt.Columns.Add(new DataColumn("Col4", typeof(string)));
dt.Columns.Add(new DataColumn("Col5", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Col1"] = string.Empty;
dr["Col2"] = string.Empty;
dr["Col3"] = string.Empty;
dr["Col4"] = string.Empty;
dr["Col5"] = string.Empty;
dt.Rows.Add(dr);

I think its work.


Refer this :

http://www.aspsnippets.com/Articles/Add-new-Row-to-GridView-on-Button-Click-in-ASPNet.aspx[^]


Dynamically adding and deleting rows from ASP.NET GridView[^]


HI, hope this link will help you:

How to insert blank row in the grid view in asp.net[^]


这篇关于使用C#向gridview添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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