hi
i have 2 question about Datagrid & Datagridview.
1_how i can add a new column or row to DataGrid ?
2_how is dinamic update (during run )the dataset?
i have c# code about them.
thanks.
Loading
hi
i have 2 question about Datagrid & Datagridview.
1_how i can add a new column or row to DataGrid ?
2_how is dinamic update (during run )the dataset?
i have c# code about them.
thanks.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sean GPosted Jul 18, 2007, 9:35 AM
1) you'll need a business object/business data to manage the data within your DataGrid. Its always nice to keep the logic seperate. Im not sure how your doing it, but here is a technique by which data is added to and managed within a DataSet object. Your can then use this to manipulate your data and bind it to your grid.
// Init...
DataRow newRow = null;
DataSet ds = new DataSet();
// Setup table and columns...
ds.Tables.Add("items");
ds.Tables["items"].Columns.Add("Column 1");
ds.Tables["items"].Columns.Add("Column 2");
// Add new data row data
newRow = ds.Tables["items"].NewRow();
newRow["Column 1"] = "value";
newRow["Column 2"] = "value";
ds.Tables["items"].Rows.Add(newRow);
// Bind it up to datagrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();