Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create gridview for insert rows at runtime not from datasource.

For example I want get the records like Pname,qty, rate
so when i give this details the amount is automatically calculated in each row

finally i calculate the total amount ant tax

So I want above process in on the grid. So anybody help
So the I want to select pname in gridview which is combobox column like vb.net

Anybody help for creating this gridview
Posted
Updated 15-Mar-12 23:14pm
v3

1 solution

Try like this

C#
//Create a DataTable instance
DataTable table = new DataTable();
//Create columns for this DataTable
DataColumn col1 = new DataColumn("ID");
//Define DataType of the Columns
col1.DataType = System.Type.GetType("System.Int");
//Add All These Columns into DataTable table
table.Columns.Add(col1);
//Create a Row in the DataTable table
DataRow row = table.NewRow();
//Fill All Columns with Data
row[col1] = 1;
//Add the Row into DataTable
table.Rows.Add(row);
//Bind this DataTable to a GridView
gvTest.DataSource = table;
gvTest.DataBind();


You need to change this as per your needs. while on each Page_Load DataTable might lose its value. So keep the datatable in a session.
Has seen the exact requirement and sample somewhere. You can google it and find it out.
 
Share this answer
 
Comments
devausha 16-Mar-12 6:59am    
Thank you very much for your Reply. This is very userful. I want this columns are textbox column or combobox coloumns for Editing. How to do it. Please help me
Baji Jabbar 16-Mar-12 7:01am    
You can add textbox or Combobox in EditItemTemplate of the GridView. Please give a search in google, you will get lot of examples.
devausha 17-Mar-12 0:07am    
Thank you very much. But the form is Refresh Every time I add the column. So the column is adding at 0th Position. how can i solve this problem
Baji Jabbar 20-Mar-12 6:21am    
Thats where the Session plays the role.
Baji Jabbar 20-Mar-12 6:31am    
check this link "http://www.dotnetspider.com/resources/29731-Add-text-box-at-runtime.aspx"
It uses Viewstate keep the table. You can use sessions too for the same purpose

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