Results 1 to 3 of 3

Thread: Adding new row to DataGrid

  1. #1

    Adding new row to DataGrid

    Hi,

    Is it possible to add new row to a datagrid control once it is bound to the data source?

    If so, can anyone tell me how to do it?

    Thanks,


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    6

    Re: Adding new row to DataGrid

    Hi,
    Its possible to add a row...
    U create a datatable.let it be DtTable.
    I hope u use a dataset let it be DtSet.
    Let the datagrid be DgDetails

    then use this code on click of the add button
    DtTable = DtSet.Tables["Your Table Name"];
    DtTable.Rows.Add(DtTable.NewRow());
    DgDetails.DataSource = DtTable;
    DgDetails.DataBind();

    The concept is:
    1) Create a datatable and bind the dataset
    2) Add a new row to the datatable
    3) Then bind the dataTable to the datagrid.

    Hope u got it???

    Cheers
    ----------
    Siva
    -----------
    No one is born Genius


  3. #3
    Junior Member
    Join Date
    Sep 2008
    Answers
    1

    Re: Adding new row to DataGrid

    But some error occurs...line no:29

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:


    Line 27: {
    Line 28: table = ds.Tables["Customer"];
    Line 29: table.Rows.Add(table.NewRow());
    Line 30: dgrid.DataSource = table;
    Line 31: dgrid.DataBind();


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact