Click here to Skip to main content
15,887,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to show a gridview in my page which doesn't concerns any table to be bound with it. Still it should store one Tax detail per row, as entered by user.

1. The gridview shown above should not show any records at first except the footer template of two textboxes and an Add New Record Button, when you are upto add any record.
2. Once clicked on Add New Record button it should show a row without action column.
3. (I'm having quite a hard time here)Once clicked on Add/Insert Button(separate from the gridview) store the entered record somehow.
4. Then I have to show the record in ***Another*** concrete GridView with Edit Button.
5. Once I click on edit button, control should return to my dynamic gridview page. Here, my dynamic gridview will show previously entered record with action column containing a delete button.


Can you Help Me? I don't want help with the code. Just point me in the right direction(s), please.

What I have tried:

I've tried binding it taxes table in my database, but it showed each and every entry in taxes.
Posted
Updated 21-Jul-17 1:24am
Comments
Atlapure Ambrish 21-Jul-17 7:27am    
You can use two different datatables. One to work with dynamic grid, which will be created every time and bound to this grid so it does not show any data. When you hit Add/Insert button just copy the data from this datatable to the datatable which is bound to other other grid using built-in method.

1 solution

Answers:

1. To display only the footer template when grid is empty you have to enter an empty row in Gridview and hide that row.
You should follow these steps:
Dim dt as DataTable
dt.Cols.add("column1")
dt.Cols.add("column2")
dt.Cols.add("column3")

dt.rows.Add("","","")

ViewState("table") = dt

Gridview.DataSource() = TryCast(ViewState("table"),DataTable)
DataBind()
GridView.Rows(0).Visible = False

2. When you click on Add new button. Bind a method on the button click and
do following in your method:
Dim dt AS DataTable = TryCast(ViewState("table"),DataTable)
//Add your new data inserted in your footed row in the below row
dt.Rows.Add(YourData1,YourData2,....,YourDataN)

//After inserting the row

ViewState("table") = dt

GridView.DataSource = TryCast(ViewState("table"),DataTable)
DataBind()
 
Share this answer
 
v2
Comments
Atlapure Ambrish 21-Jul-17 7:30am    
Keeping the whole datatable in viewstate is going to be very heavy and has to sent along the request/response. Also, you would like to pay attention to cast.
omerkamran 21-Jul-17 7:46am    
Well the whole technology of Webform is very heavy thats why MVC was introduced. I do agree but it will atleast solve the problem and will be easy to use for this developer.
sam_matte 22-Jul-17 5:20am    
@omerkamran Thanks, this is exactly what I was looking for. This helped me a lot.

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