Adding rows to datagrid without database

Results 1 to 2 of 2

Thread: Adding rows to datagrid without database

  1. #1
    Join Date
    Dec 1969

    Default Adding rows to datagrid without database

    Based on user form input I would like to build a datagrid row by row. I do not want to store the values in a database. I cannot seem to find (several hours of looking) a good example of how to do this just from postback info from the datagrid. There is one example on this site but it pertains to adding an add button to the grid but it depends on database for values. Thank you in advance for any assistance.

  2. #2
    Join Date
    Dec 1969

    Default RE: Adding rows to datagrid without database

    Are we talking ASP.NET here? Should have posted on the ASP.NET Forum. Anyway..... what do you have so far? What are you using for a DataSource? All you need to do is persist the source after it is initially created, retrieve the input data on PostBack, add the new data to the existing data, and rebind the the grid. I would think that a DataTable would be easiest to work with as a source. Then, simple call myTable.Rows.Add(). Here is an example form the docs:<BR>[code language="C#"]<BR>private void AddARow(DataSet ds){<BR> DataTable t;<BR> t = ds.Tables["Suppliers"];<BR> // Use the NewRow method to create a DataRow with the table&#039;s schema.<BR> DataRow newRow = t.NewRow();<BR> // Set values in the columns:<BR> newRow["CompanyID"] = "NewCompanyID";<BR> newRow["CompanyName"] = "NewCompanyName";<BR> // Add the row to the rows collection.<BR> t.Rows.Add(newRow);<BR>}<BR>[/code]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts