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

GridView with merged Column Edit/Delete

6
I have a gridview with merged columns. When I try to delete a row, my previous row is deleted. I have done this on my other webpages (with normal gridview) and its works fine there.

Can anyone please help me with this? I tried to debug and see which rowindex is it taking...and found that if I select rowindex =4 ...rowindex = 3 is selected and passed to delete query.

Please help.

Here is my code for delete:
Expand|Select|Wrap|Line Numbers
  1. protected void grdItems_RowDeleting(object sender, GridViewDeleteEventArgs e)
  2.     {
  3.         //get the id of selected row
  4.         GridViewRow row = grdItems.Rows[e.RowIndex];
  5.         if (row != null)
  6.         {
  7.             grdItems.Rows[e.RowIndex].Cells[0].FindControl("lblRowID");
  8.             Label lblRowID = (Label)grdItems.Rows[e.RowIndex].Cells[0].FindControl("lblRowID");
  9.             string id = lblRowID.Text;
  10.             DeleteRecord(id);
  11.         }
  12.         calculatetot();
  13.         populateItems();
  14.  
  15.     }
  16.     private void DeleteRecord(string ID)
  17.     {
  18.         SqlConnection myConnection = new SqlConnection(connectionString);
  19.         string sqlstmt = "delete bod_items where rowid = @rowID";
  20.  
  21.         try
  22.         {
  23.             myConnection.Open();
  24.             SqlCommand cmd = new SqlCommand(sqlstmt, myConnection);
  25.             cmd.Parameters.AddWithValue("@rowid", ID);
  26.             cmd.CommandType = CommandType.Text;
  27.             cmd.ExecuteNonQuery();
  28.         }
  29.         catch (Exception err)
  30.         {
  31.             lblResult.Text = "Error deleting record. ";
  32.             lblResult.Text += err.Message;
  33.         }
  34.         finally
  35.         {
  36.             myConnection.Close();
  37.         }
  38.  
  39.     }
  40.  
Jul 30 '10 #1
0 1035

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

Similar topics

1
by: Qnavry | last post by:
I am creating one page to edit, delete, and add data to a database. The Add code works but the Edit and Delete do not. What am I doing wrong? If you need more code let me know. Thanks Code:...
1
by: | last post by:
I'm wondering if it's possible, outside of the declaration of an ASP.NET 2.0 GridView, to programmatically style individual columns. For example, I might want to make the text in a particular...
12
by: dennist685 | last post by:
Can't edit, delete or add row in an Access database in a website 2003 When I implement a walkthrough using Northwind I have no trouble doing this. Also, in a windowsforms project I have no...
2
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course...
2
by: keithb | last post by:
I have dropdown list in a gridview column edit template. It works OK, except when I edit a row, the dropdown list does not initialize to the existing value that shows in the textbox that displays...
1
by: Frank Milverckowitz | last post by:
Hi, I'm trying to do something common and what should be simple using the GridView "Add Columns" feature in Visual Studio 2005. All I want to do is add a Hyperlink column that will take the...
1
by: Neven Klofutar | last post by:
Hi, I have a questin regarding GridView, Template column and Checkbox in it. I'm working on a project that has several "client" applications entering data into DB, and one "admin" application...
4
by: TS | last post by:
I have a headerText for a header column that is "Page<br>Name". it puts a <brto force a line break, but the < and get encoded to &lt; and &gt; thus negating its effect as an html control and doesn't...
0
by: dan | last post by:
Hi, I have a multi-line textbox in a gridview when in edit mode. The textbox (rendered as textarea in browser) set cols to 20 by default. I'd like the textbox to 'adjust' itself to the width...
2
by: yahshuatwo | last post by:
How can you display an icon the gridview cell column which is dependent on the text value of an adjacent column. Also, I setup the asp template,item and image controls, do i need to set the imgURL...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.