469,935 Members | 1,924 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

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

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.Ite ms.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>
Nov 18 '05 #1
2 1818
"Praveen Balanagendra via .NET 247" <an*******@dotnet247.com> wrote in
message news:e4**************@TK2MSFTNGP10.phx.gbl...
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.Ite ms.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
Nov 18 '05 #2
Jos
"Praveen Balanagendra via .NET 247" <an*******@dotnet247.com> wrote in
message news:e4**************@TK2MSFTNGP10.phx.gbl...
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.Ite ms.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,ListItemTyp e.Item);

--

Jos
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jim Heavey | last post: by
4 posts views Thread by Steve | last post: by
reply views Thread by Guy W via DotNetMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.