Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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);
 
Share this answer
 
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900