I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not

Discussion in 'ASP .Net' started by Praveen Balanagendra via .NET 247, Jun 5, 2004.

  1. here is the source code

    private void AddRow()
    {
    TableCell tc = new TableCell();
    tc.Controls.Add(new LiteralControl("NewRow"));

    DataGridItem di = new DataGridItem(DataGrid1.Items.Count+1,DataGrid1.Items.Count+1,ListItemType.Item);
    di.Cells.Add(tc);
    di.Cells.Add(tc1);
    Table t = (Table)DataGrid1.Controls[0];
    t.Rows.Add(di);
    }

    before i call this function, say i have 5 rows in my datagrid. After this function is called, which adds a new row to datagrid, still my datagrid shows it has only 5 rows....what could be the reason

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>S7kGQXam2kS4+j8Azj4KbA==</Id>
    Praveen Balanagendra via .NET 247, Jun 5, 2004
    #1
    1. Advertising

  2. "Praveen Balanagendra via .NET 247" <> wrote in
    message news:...
    > here is the source code
    >
    > private void AddRow()
    > {
    > TableCell tc = new TableCell();
    > tc.Controls.Add(new LiteralControl("NewRow"));
    >
    > DataGridItem di = new

    DataGridItem(DataGrid1.Items.Count+1,DataGrid1.Items.Count+1,ListItemType.It
    em);
    > di.Cells.Add(tc);
    > di.Cells.Add(tc1);
    > Table t = (Table)DataGrid1.Controls[0];
    > t.Rows.Add(di);
    > }


    This code isn't adding rows to a datagrid, it's adding rows to a table which
    happens to be in the datagrid.

    Have you set the DataSource property of the datagrid? If so, then all the
    rows will come from the datasource, and the way to add a row to the grid
    would be to add the row to the source.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 5, 2004
    #2
    1. Advertising

  3. Praveen Balanagendra via .NET 247

    Jos Guest

    "Praveen Balanagendra via .NET 247" <> wrote in
    message news:...
    > here is the source code
    >
    > private void AddRow()
    > {
    > TableCell tc = new TableCell();
    > tc.Controls.Add(new LiteralControl("NewRow"));
    >
    > DataGridItem di = new

    DataGridItem(DataGrid1.Items.Count+1,DataGrid1.Items.Count+1,ListItemType.It
    em);
    > di.Cells.Add(tc);
    > di.Cells.Add(tc1);
    > Table t = (Table)DataGrid1.Controls[0];
    > t.Rows.Add(di);
    > }
    >
    > before i call this function, say i have 5 rows in my datagrid. After this

    function is called, which adds a new row to datagrid, still my datagrid
    shows it has only 5 rows....what could be the reason


    1) AddRow() is never called
    2) DataBind() is being called after AddRow()
    3) I'm not sure this could be the reason, but try:
    new DataGridItem(DataGrid1.Items.Count+1,0,ListItemType.Item);

    --

    Jos
    Jos, Jun 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lucky
    Replies:
    0
    Views:
    499
    lucky
    Jan 12, 2005
  2. aliciahogue
    Replies:
    0
    Views:
    598
    aliciahogue
    Oct 20, 2009
  3. QUASAR
    Replies:
    6
    Views:
    406
    QUASAR
    Jan 17, 2004
  4. D
    Replies:
    0
    Views:
    197
  5. Sameeksha
    Replies:
    0
    Views:
    109
    Sameeksha
    Apr 7, 2005
Loading...

Share This Page