473,395 Members | 1,418 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,395 software developers and data experts.

Deleting a row in datagrid

hi,

Can anyone please help me solve the problem m facing with the datagrid.
I want to delete a row in the datagrid and correspondingly i want that data to be deleted in database .

thanks,
Mar 12 '08 #1
4 1542
in the datagrid add one more column with links for each row
for the link (onclick event) write the code to delete the row based on the id of that perticular row from the database table

at the end redirect the page to the same page so the item deleted will not be shown in the grid, or else u have to refresh the page to see the effect.
Mar 12 '08 #2
hi,

i have added that delete button column and i have written the code ..its not working and after deleting i have binded the datagrid so hlep me with this.
thank u.
Mar 13 '08 #3
How to delete a row from datagrid?

button1_click()
{
int i=dataGridView1.CurrentRow.Index;
dataGridView1.Rows.RemoveAt(i);
}

another methos is:

int i=dataGridView1.CurrentRow.Index;
DataTable dt = dataGridView1.DataSource as DataTable;
DataRow rw=dt.Rows[i];
rw.Delete();
Sep 19 '08 #4
how to delete a row in the datagrid and correspondingly that data to be deleted in database ?


private void delete_Click(object sender, EventArgs e)
{
string ss = dataGridView1.CurrentRow.Cells[0].Value.ToString();
con.Open();
string s = "delete from stutbl where regno='" + ss + "'";
SqlCommand cmd = new SqlCommand(s, con);
cmd.ExecuteNonQuery();
}
Sep 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is...
1
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
2
by: Alex K. | last post by:
I am using datagrid bound to a datatable: DataTable dt = ...; MyGrid.DataSource = new DataView(dt); Now I am trying to intercept delete operation, when user highlights a row and presses...
0
by: Hrvoje Vrbanc | last post by:
Hello, this is a problem I came upon while building a site based on MCMS 2002 but it's not strictly MCMS-oriented: I have a page that displays a certain content in presentation mode but when an...
2
by: NDady via DotNetMonster.com | last post by:
Hi, I have a datagrid populated from a dataset. On every row in the grid I have a delete button. When the user presses on the delete button I remove the row from the dataset and rebind the...
0
by: Robert Batt | last post by:
Hello I have a problem deleting rows from a datagrid that is bound to a dataset. The datagrid updates and inserts just fin so the binding to the dataset must be ok. However when I try to delete a...
1
by: Robert Batt | last post by:
Hello, I have a problem deleting from a datagrid bound to a dataset. then datagrid is bound as follows MyDatagrid.DataSource = Mydataset.Tables(strtable this works fine for adding and...
10
by: Nick | last post by:
Hello, Please pardon my ignorance as I'm sure this is easy to do. I have a datagrid where I want to let the user delete columns. I added a context menu to the datagrid that has a delete option....
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.