Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   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 (http://www.velocityreviews.com/forums/t79816-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.html)

Praveen Balanagendra via .NET 247 06-05-2004 07:24 PM

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>

John Saunders 06-05-2004 08:18 PM

Re: 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
 
"Praveen Balanagendra via .NET 247" <anonymous@dotnet247.com> wrote in
message news:e4LF2KzSEHA.3872@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



Jos 06-06-2004 07:16 AM

Re: 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
 
"Praveen Balanagendra via .NET 247" <anonymous@dotnet247.com> wrote in
message news:e4LF2KzSEHA.3872@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




All times are GMT. The time now is 01:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.