473,657 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Edit, Delete and Cancel data in Datagrid

33 New Member
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 4327
Pooja Shukla
1 New Member
Hi Kuldeep,
With these lines of code u would be able to do it....

private void datagrid1_EditC ommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
datagrid1.EditI temIndex = e.Item.ItemInde x;
datagrid1.DataB ind();
}

private void datagrid1_Delet eCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
SqlCommandBuild er cb=new SqlCommandBuild er(DataAdapterO bject);

// Delete Corresponding row
ds.Tables [0].Rows [e.Item.DataSetI ndex].Delete();
DataAdapterObje ct.Update (ds);
Page.DataBind ();
}

private void datagrid1_Cance lCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
datagrid1.EditI temIndex = -1;
datagrid1.DataB ind();
}

private void datagrid1_Updat eCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
TableCell tc = e.Item.Cells[2];

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

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

SqlCommandBuild er scb = new SqlCommandBuild er(DataAdapterO bject);

DataAdapterObje ct.Update(ds);

// Edit operation should be cancelled
datagrid1.EditI temIndex = -1;
datagrid1.DataB ind();
}


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
kuldeep singh sethi
33 New Member
Hi Kuldeep,
With these lines of code u would be able to do it....

private void datagrid1_EditC ommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
datagrid1.EditI temIndex = e.Item.ItemInde x;
datagrid1.DataB ind();
}

private void datagrid1_Delet eCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
SqlCommandBuild er cb=new SqlCommandBuild er(DataAdapterO bject);

// Delete Corresponding row
ds.Tables [0].Rows [e.Item.DataSetI ndex].Delete();
DataAdapterObje ct.Update (ds);
Page.DataBind ();
}

private void datagrid1_Cance lCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
datagrid1.EditI temIndex = -1;
datagrid1.DataB ind();
}

private void datagrid1_Updat eCommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
TableCell tc = e.Item.Cells[2];

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

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

SqlCommandBuild er scb = new SqlCommandBuild er(DataAdapterO bject);

DataAdapterObje ct.Update(ds);

// Edit operation should be cancelled
datagrid1.EditI temIndex = -1;
datagrid1.DataB ind();
}


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
2458
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 insert,delete and edit fields in a datagrid at runtime Please be kind enough to help me Thanks Rameshika
0
3100
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. However, the DataGrid begins to get very cumbersome as the number of columns of data you present increases. Anything more than half a dozen columns or so and you probably induce horizontal scrolling - a real no-no for me. If you put such a...
4
4406
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: <asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" CssClass="clickable"Width="50px" /> When I edit a row, the Update/Cancel links don't show up.
3
2278
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 "Submit" button, only those records are displayed where company name matches with user input. I need the datagrid to be editable. For this i used the walkthrough from ..NET "Using a datagrid for reading & writing data to database" or it was some...
4
6941
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
2846
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 appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
0
1195
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 something wrong in the EditItemTemplate or should I be binding, somehow, separately in the vb code? Please view my code, below, and the notes in green for clarification of what I've done, and what is/is not working, here. Thanks in advance.
0
3221
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
2714
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.