Filling dataset with form data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a few textboxes to hold x, y, z dimensions and weight per item. The
user may have different number of items so I will have one set of these
textboxes with an add button. Upon click, I would like to show the data in a
tabular form with proper headings for each of the items on the same page
before finally submitting it to the DB. Is there any way I can use DataTable,
DataGrid etc to show the data in a neat format?
I searched the net for my question. I need to know:
- how to use datagrid to send information to it.
- how to retrieve it to submit it to the DB.
TIA
 
I actually want to save the data into a datagrid first(using the inputs from
different textboxes) and then eventually submit it to the DB for the first
time. The webpage you recommended seems to only have examples of filling the
datagrid with a table in the DB. Please advice if I am wrong.

Thanks.
 
Create a DataDaset or DataTable, populate it with your data from TextBoxes
and bind it to the DataGrid..
Something like that (not tested)

//Create DateTable
DataTable dt = new DataTable("table");

//add to columns collection
DataColumn dc = dt.Columns.Add("Column 1");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

dc = dt.Columns.Add("Column 2");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

dc = dt.Columns.Add("Column 3");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

//Update values
DataRow dataRow = dt.NewRow();
dataRow["Column 1"] = textBox1.Text;
....

Bind it to the grid:

dataGrid.DataSource - dt;
 
DataGrid only shows data from DataSource, it does not have data storage at
all.
You can't "save the data into a datagrid" just like you can't pour water
into the bucket's reflection in the mirror.
You should add data to the grid's data source (e.g. DataTable) and push
this update to the data base at your convenience.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: Filling dataset with form data
thread-index: AcWRPe4ZpmMtAeNOQCCXCYBsFbUz3w==
X-WBNR-Posting-Host: 68.23.146.92
From: "=?Utf-8?B?bGVhcm5pbmdORVQ=?="
 
Hi
Your reply did help me databind the datatable to datagrid, but I have
another question: I create the datatable in page_load and databind it to a
datagrid. In my btnAdd_Click method( which should just add another row with
the new textbox values), I am unable to use the column names. I even tried
declaring the datatable in class scope. Is there a way I can databind the
datagrid back to a datatable in that method, add a row and at the end,
databind the datatable back again? I hope you get what I'm saying. Thanks
again.
 
Back
Top