在gridview中如何使用asp.net添加新行 [英] in gridview how to add new row using asp.net

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

问题描述

在gridview中如下





产品编号产品名称Validtiy销售人员



P0001 Xanso 1年拉姆







然后我想在asp中添加另一行.net我怎么能用csharp。



Rgds,

Narasiman P.

In gridview as follows


Product ID Proudct Name Validtiy Sales person

P0001 Xanso 1 year Ram



then i want to add another row in asp.net for that how can i do using csharp.

Rgds,
Narasiman P.

推荐答案

下面的代码将帮助你



Below code will help you

GridViewRow rw = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
           TableCell rowCell;

           int colCount = GridView1.Columns.Count;
           //if your not providing columns at design time in .aspx file
           //then you need provide value for colCount manullay
           //like below commented line
           //int colCount = 3;


           for (int i = 0; i < colCount; i++)
           {
               rowCell = new TableCell();
               rowCell.Text = "celltext";
               rw.Cells.Add(rowCell);
           }
           GridView1.Controls[0].Controls.Add(rw);


步骤非常简单。首先,您需要创建一个gridview行并使用所需数据填充它。之后,将其添加到gridview中。示例代码如下:



int rowNum = grd.Count;



GridViewRow row = new GridViewRow (rowNum,rowNum,DataControlRowType.DataRow,DataControlRowState.Normal);



//现在为该行创建单元格。

TableCell tableCell = new TableCell();

tableCell.Text =此处为单元格的文字;



row.Cells.Add(tableCell);



grd.Controls [0] .Controls.AddAt(rowCount,row);
Steps are very simple. First of all you need to create a gridview row and populate it with the required data. After that, add it in the gridview. Sample code is as below:

int rowNum = grd.Count;

GridViewRow row = new GridViewRow(rowNum, rowNum, DataControlRowType.DataRow, DataControlRowState.Normal);

// now create cells for the row.
TableCell tableCell = new TableCell();
tableCell.Text = "Text for cell here";

row.Cells.Add(tableCell);

grd.Controls[0].Controls.AddAt(rowCount, row);


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

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