473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

adding a row on a datagrid

Hi,
I'm trying to Insert a new Row on a dagrid. When I did a google
search, I got an example on this address: http://www.codeproject.com/ASPNET_DataGrid.asp.
I've done mycode as follows:

private void Fill()
{
DataSet ds=new DataSet();
SqlDataAdapter adapter =new SqlDataAdapter("select * from DashBoard",
con);
adapter.Fill(ds);
}
private void Bind()
{
DataSet ds=new DataSet();
dgis.DataSource = ds;
dgis.DataBind();
}
private void InsertEmpty()
{
DataSet table=new DataSet();
Table.Rows.InsertAt(Table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{

dgis.EditItemIndex = 0;

EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Insert";

Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object
source,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
{
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;

case "Update":
break;

case "Cancel":
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Update";
break;

case "Edit":
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}

Fill();
Bind();
}

On compiling I get this error

-'System.Web.UI.WebControls.Table' does not contain a definition for
'NewRow'
-'System.Web.UI.WebControls.TableRowCollection' does not contain a
definition for 'InsertAt'
-'An object reference is required for the nonstatic field, method, or
property 'System.Web.UI.WebControls.Table.Rows'

Where could I be going wrong?

Feb 26 '07 #1
3 2415
try adding a row to the TABLE itself - not the dataset
Dim dr As DataRow = DataTable.NewRow()
DataTable.Rows.InsertAt(dr, 0)

Then, rebind the table to the datagrid

btw - which version of DotNet are you using?
--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com

"rcoco" <nc******@yahoo.cawrote in message
news:11**********************@z35g2000cwz.googlegr oups.com...
Hi,
I'm trying to Insert a new Row on a dagrid. When I did a google
search, I got an example on this address:
http://www.codeproject.com/ASPNET_DataGrid.asp.
I've done mycode as follows:

private void Fill()
{
DataSet ds=new DataSet();
SqlDataAdapter adapter =new SqlDataAdapter("select * from DashBoard",
con);
adapter.Fill(ds);
}
private void Bind()
{
DataSet ds=new DataSet();
dgis.DataSource = ds;
dgis.DataBind();
}
private void InsertEmpty()
{
DataSet table=new DataSet();
Table.Rows.InsertAt(Table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{

dgis.EditItemIndex = 0;

EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Insert";

Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object
source,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
{
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;

case "Update":
break;

case "Cancel":
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Update";
break;

case "Edit":
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}

Fill();
Bind();
}

On compiling I get this error

-'System.Web.UI.WebControls.Table' does not contain a definition for
'NewRow'
-'System.Web.UI.WebControls.TableRowCollection' does not contain a
definition for 'InsertAt'
-'An object reference is required for the nonstatic field, method, or
property 'System.Web.UI.WebControls.Table.Rows'

Where could I be going wrong?

Feb 26 '07 #2
Are you sure you got this exact code from somebody's article?

private void InsertEmpty()
{
DataSet table=new DataSet();
Table.Rows.InsertAt(Table.NewRow(), 0);
}

What the above does is (as David pointed out) attempt to Insert a Row on a
DataSet, which has no "Rows" collection. Your first line should look like:
DataTable table = new DataTable();

the DataTable class DOES have a Rows collection.

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"rcoco" wrote:
Hi,
I'm trying to Insert a new Row on a dagrid. When I did a google
search, I got an example on this address: http://www.codeproject.com/ASPNET_DataGrid.asp.
I've done mycode as follows:

private void Fill()
{
DataSet ds=new DataSet();
SqlDataAdapter adapter =new SqlDataAdapter("select * from DashBoard",
con);
adapter.Fill(ds);
}
private void Bind()
{
DataSet ds=new DataSet();
dgis.DataSource = ds;
dgis.DataBind();
}
private void InsertEmpty()
{
DataSet table=new DataSet();
Table.Rows.InsertAt(Table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{

dgis.EditItemIndex = 0;

EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Insert";

Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object
source,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
{
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;

case "Update":
break;

case "Cancel":
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Update";
break;

case "Edit":
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}

Fill();
Bind();
}

On compiling I get this error

-'System.Web.UI.WebControls.Table' does not contain a definition for
'NewRow'
-'System.Web.UI.WebControls.TableRowCollection' does not contain a
definition for 'InsertAt'
-'An object reference is required for the nonstatic field, method, or
property 'System.Web.UI.WebControls.Table.Rows'

Where could I be going wrong?

Feb 26 '07 #3
Thanks all,
That was actually my problem. This is what I was supposed to do and it
worked
private void InsertEmpty()
{
DataTable table = new DataTable();
table.Rows.InsertAt(table.NewRow(), 0);
}

But I got another problem When I run my form, I'm only able to see the
header of the datagrid and cannot see the containt of the table. Could
some one be knowing why? Thanks.

Feb 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
5
by: Phil Townsend | last post by:
I need to add a button to a datagrid. I have tried using the ButtonColumn and have also tried adding a button to a templatecolumn > itemtemplate. Whatever I have tried doesn't work, nor does it...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: Praveen Balanagendra via .NET 247 | last post by:
here is the source code private void AddRow() { TableCell tc = new TableCell(); tc.Controls.Add(new LiteralControl("NewRow")); DataGridItem di = new...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
1
by: Tor Inge Rislaa | last post by:
Adding HTML tags to data from SQL server When dragging a table on to a web form in an ASP.NET 2.0 application, the connection is established and the data is displayed in a DataGrid. Is it...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.