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

Unable to delete a row in a gridview

103 100+
Hi all,

i got an error "System.NotSupportedException: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified"
when i try to delete a row..

the code is given below..
Expand|Select|Wrap|Line Numbers
  1.   public void DeleteRecordByID(int catid)
  2.     {
  3.         try
  4.         {
  5.             con = new SqlConnection(connection);
  6.             con.Open();
  7.             SqlCommand cmd2 = new SqlCommand("delete from Categories where CategoryID=" + cid + "", con);
  8.             cmd2.ExecuteNonQuery();
  9.             con.Close();
  10.             GridView1.DataBind();
  11.         }
  12.         catch (Exception)
  13.         {
  14.         }
  15.  
  16.  
  17.     }
  18.  
  19.  
  20.  
  21.  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  22.     {
  23.         try
  24.         {
  25.             if (e.CommandName == "Delete")
  26.             {
  27.                 int categoryID = Convert.ToInt32(e.CommandArgument);
  28.                 DeleteRecordByID(categoryID);
  29.  
  30.             }
  31.         }
  32.         catch (Exception)
  33.         {
  34.         }
  35.  
  36.     }
  37.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  38.     {
  39.         try
  40.         {
  41.             if (e.Row.RowType == DataControlRowType.DataRow)
  42.             {
  43.                 LinkButton L = (LinkButton)e.Row.FindControl("LinkButton1");
  44.                 L.Attributes.Add("onclick", "javascript:return" + "confirm('Are you sure you want to delete this record " + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')");
  45.  
  46.             }
  47.         }
  48.         catch (Exception)
  49.         {
  50.         }
  51.  
  52.     }
  53.     protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
  54.     {
  55.  
  56.     }
  57.     protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
  58.     {
  59.         try
  60.         {
  61.             int categoryID = (int)GridView1.DataKeys[e.RowIndex].Value;
  62.             DeleteRecordByID(categoryID);
  63.         }
  64.         catch (Exception)
  65.         {
  66.         }
  67.  
  68.     }
  69.  
  70.  
Please help me to solve this problem...
Sep 26 '07 #1
2 8234
Frinavale
9,735 Expert Mod 8TB
Hi all,

i got an error "System.NotSupportedException: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified"
when i try to delete a row..

the code is given below..
Please help me to solve this problem...
I do not see a variable named SqlDataSource1 in your code.
Could you please specify which line you think is causing the problem...

According to MSDN this exception is thrown "when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality".

The only recommendation I have for your right now is to make sure that your Data Source allows you to perform a delete.


-Frinny
Sep 26 '07 #2
moggaa
13
hi

on your data gird add control linked delete then in delete command
Expand|Select|Wrap|Line Numbers
  1. Dim SQL As String
  2.         SQL = "delete from tablename where id= " & e.Item.Cells(0).Text & " "
thank's

Maged
Sep 27 '07 #3

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
0
by: Terence | last post by:
Hi, I have a web user control which includes a gridview and a sqldatasource. It also has a property called TableName which is used to populate the gridview. However, i'm running into a problem...
0
by: Steve | last post by:
I have a gridview which uses an objectdatasource for its select and delete. The delete command uses the function below. The delete itself works but the extra logic which requires parameters...
4
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
0
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
by: sana krishna | last post by:
Hai, Pls anyone help me........................... I am using ASP.NET(C#). I want to display the data in a gridview and make the gridview to become editable and insert and delete. But i can't...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
2
by: Danielle | last post by:
Hello all - Thank you in advance for any help you are able to provide. I am populating a gridview from a stored procuedure. The returned data is a name, phone number, email and guid of a...
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: 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
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
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,...

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.