spr
spr

Reputation: 322

gridview creation

In asp.net Grid View, I want to add rows by entering the values through edit text i.e, with out using database.
Initially, one empty row will be displayed with "add" button as one column.
When I click "add" button, text boxes will be shown in all columns to enter values and the "add" button field contains "save" and "cancel" button.
When I click "save" the values must be displayed in next row as labels.

Can any one guide me on this issue?

Upvotes: 1

Views: 137

Answers (2)

शेखर
शेखर

Reputation: 17614

You can set the data source to a datatable that you can build up in code with whatever you like.

Here's a link showing how to build a datatable in code...

http://www.aspnettutorials.com/tutorials/controls/data-table-csharp.aspx

You would then add rows to the table and set it to the data source for your gridview.

You can also set a gridview's data source with a list:

http://www.aspnettutorials.com/tutorials/advanced/ilist-interface-aspnet2-vb.aspx

Edit 1

Few helpful links
how to insert data in to grid view using asp.net without database

Upvotes: 1

spryce
spryce

Reputation: 607

Sure. I would do something like this:

1) Setup your GridView template

2) When a user has filled in the empty text boxes and clicks the "add" button, catch the event, create a new row in a DataTable and store the values

3) Create a new row at position zero and add empty strings

table.Rows.InsertAt(row, 0);

4) Databind the DataTable to the GridView

6) Each time a row is added the GridView will grow, just reinsert a blank row (plus your 'add' link) at position zero.

You should probably have a go at it and if you don't achieve the results your looking for post your code. Someone will point you in the right direction.

Upvotes: 1

Related Questions