473,405 Members | 2,272 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,405 software developers and data experts.

How to Edit, Delete and Cancel data in Datagrid

Hi all


I want to know that how to edit,Delete and cancel data in datagrid using c#. Any body would like to help me plz for this.


kuldeep singh sethi
Nov 9 '06 #1
2 4311
Hi Kuldeep,
With these lines of code u would be able to do it....

private void datagrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = e.Item.ItemIndex;
datagrid1.DataBind();
}

private void datagrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlCommandBuilder cb=new SqlCommandBuilder(DataAdapterObject);

// Delete Corresponding row
ds.Tables [0].Rows [e.Item.DataSetIndex].Delete();
DataAdapterObject.Update (ds);
Page.DataBind ();
}

private void datagrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}

private void datagrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TableCell tc = e.Item.Cells[2];

string s = ((TextBox)tc.Controls[0]).Text;

ds.Tables[0].Rows[e.Item.DataSetIndex]["Role"] = s;

SqlCommandBuilder scb = new SqlCommandBuilder(DataAdapterObject);

DataAdapterObject.Update(ds);

// Edit operation should be cancelled
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}


But i think your problem is different because that much u can get in help document also. So reply it u need something different.

Pooja Shukla



Hi all


I want to know that how to edit,Delete and cancel data in datagrid using c#. Any body would like to help me plz for this.


kuldeep singh sethi
Nov 10 '06 #2
Hi Kuldeep,
With these lines of code u would be able to do it....

private void datagrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = e.Item.ItemIndex;
datagrid1.DataBind();
}

private void datagrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlCommandBuilder cb=new SqlCommandBuilder(DataAdapterObject);

// Delete Corresponding row
ds.Tables [0].Rows [e.Item.DataSetIndex].Delete();
DataAdapterObject.Update (ds);
Page.DataBind ();
}

private void datagrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}

private void datagrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TableCell tc = e.Item.Cells[2];

string s = ((TextBox)tc.Controls[0]).Text;

ds.Tables[0].Rows[e.Item.DataSetIndex]["Role"] = s;

SqlCommandBuilder scb = new SqlCommandBuilder(DataAdapterObject);

DataAdapterObject.Update(ds);

// Edit operation should be cancelled
datagrid1.EditItemIndex = -1;
datagrid1.DataBind();
}


But i think your problem is different because that much u can get in help document also. So reply it u need something different.

Pooja Shukla


Hi

Thanks to give me this example with code.
Now I want to add dropdown list in datagrid and also want to working can i do it.

Thanks Again


Kuldeep singh sethi
Nov 17 '06 #3

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

Similar topics

3
by: Rameshika | last post by:
Hi All How can I select a particular row in a datagrid.Where when the user double clicks the data in that row should appear in the corresponding text boxes in runtime And how can the user...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
4
by: DC | last post by:
Newbie's question about .NET datagrid If I use: <asp:EditCommandColumn></asp:EditCommandColumn> When I edit a row, it will automatically show Update and Cancel Link. But when I use:...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
4
by: rkbnair | last post by:
Is there any way to display an image button instead of the traditional Edit/Update/Cancel push button in a datagrid (with bound data)?
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
0
by: bh | last post by:
I'm trying to edit data in a datagrid through a dropdown list with different id/text values. The problem comes in when I click the edit button & nothing appears to be happening. Did I do...
0
by: kuldeep singh sethi | last post by:
Hi all I want to know that how to edit,Delete and cancel data in datagrid using c#. Any body would like to help me plz for this. kuldeep singh sethi
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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:
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
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...

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.