Skip to content

DataGrid

mahdieh

Asked Jul 18, 2007, 2:41 AM EDT1 answer
Share
LinkedInX

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.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Im not sure what your saying in (2) your english isnt too great, can you try and re-phrase
    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();
    0