简体   繁体   中英

Set the content of gridview cell by cell

How do you set the content of single cell of gridview. For example I would like to set the grid cell at row 2, column 3 = 67 like winforms component one grid provides this functionality as c1grid(2,3) = 67. same functionality i need in my app.Many times it is nice to be able to do a series of calculations and write the results directly to the grid. I don't want to bind to anything and I am only interested in the values of a single cell.

can i do this with default gridview in asp.net ? or do i need to use any third party grid ? Which third party grid provides such functionality ? i have seen pdf for component one grid for asp.net(wijmo).But i havent seen any thing that will satisfy my requirement.

Any help? any Idea?

Create your own

DataTable dt = new DataTable("Table");

Add Columns What you want

dt.Columns.Add("Column1",typeOf(int));

Now Add new Rows to your dt

System.Data.DataRow row = dt.NewRow();
row.BeginEdit();
row["Col1"] = 10;
row.AcceptChanges();
dt.Rows.Add(row);

So by wrapping all above in one it will be

System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Col1", typeof(int));
for (int index = 0; index < 10; index++)
{
     System.Data.DataRow row = dt.NewRow();
     row.BeginEdit();
     row["Col1"] = 10;
     row.AcceptChanges();
     dt.Rows.Add(row);
}
dt.AcceptChanges();

Now bind to your grid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM