IT Community - Software Programming, Web Development and Technical Support

Delete command error

This is a discussion on Delete command error within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, In a page i placed a grid called gridview1 and bound it with data from the DB. I bounded ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 04-07-2008, 10:49 PM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Question Delete command error

Hi,
In a page i placed a grid called gridview1 and bound it with data from the DB. I bounded the data from DB from the code behind file. Then added an imagebutton in the itemtemplete for deleting a row.The function for deleting the row was done by using C# in the code behind file. How can i call the delete function from the code-behind file to this imagebutton's click event.

My code as follows. But it is not calling the delete function.

Presentation file

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting1">
<Columns>
<asp:BoundField DataField="Title_drawings" HeaderText="Title_drawings" SortExpression="Title_drawings" />
<asp:BoundField DataField="Type_drawings" HeaderText="Type_drawings" SortExpression="Type_drawings" />
<asp:BoundField DataField="filename" HeaderText="filename" SortExpression="filename" />
<asp:BoundField DataField="Date_upload" HeaderText="Date_upload" SortExpression="Date_upload" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="deleterow" runat="server" CommandName="Delete" ImageUrl="delete1.gif"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



Code-behind file



public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon = new SqlConnection("Data Source=SYSTEM-3\\SQLEXPRESS;Initial Catalog=project_mgt;Integrated Security=True");
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();


public void display()
{
ds.Dispose();
ds.Clear();
SqlParameter[] @param = new SqlParameter[1];
@param[0] = new SqlParameter("@PID", "1");
SqlDataAdapter sqladapter = new SqlDataAdapter("select title_drawings,type_drawings,filename,Date_upload, comments from drawing_details where Project_ID=@PID", sqlcon);
for (int i = 0; i <= param.Length - 1; i++)
{
sqladapter.SelectCommand.Parameters.Add(@param[i]);
}
if (param.Length >= 1)
{
sqladapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
GridView1.Dispose();
}


protected void Page_Load(object sender, EventArgs e)
{

display();

}


protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
string s = GridView1.Rows[e.RowIndex].Cells[1].Text;
cmd.CommandText = "delete from drawing_details where Title_drawings='" + s + "'";
cmd.Connection = sqlcon;
sqlcon.Open();
cmd.ExecuteNonQuery();
sqlcon.Close();
}
}
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 04-07-2008, 11:01 PM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Default Re: Delete command error

My problem is, i want an icon to be displayed on each and every row of the grid.
While clicking this icon the row must want to be deleted.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 04-08-2008, 12:17 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Delete command error

Hi Kirubha,

I have attached the sample website that contains the datagrid and you can edit and delete the row using this sample.

Hope this helps....
Attached Files
File Type: zip datagrid.zip (3.3 KB, 5 views)
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 04-08-2008, 12:31 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Question Re: Delete command error

But i want a picture in the place of the command "Delete".
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 04-08-2008, 12:36 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Question Re: Delete command error

I already have this code for deleting. But while using the imagebutton, it is not working. I want an image in the palce of the "Delete" command.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 04-08-2008, 12:46 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Delete command error

Hi Kirubha,

Use imagebutton instead of using Button.

<asp:ImageButton id="ImageButton1" runat="server"
ImageUrl="url" />
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 04-08-2008, 02:01 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Smile Re: Delete command error

Thank you balu,
I did it.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: command line error MIDL1001 : cannot open input file wincodec.idl midl Mramesh C# Programming 0 02-18-2008 10:07 PM
How to delete memcache? Kamalakannan PHP Programming 11 10-25-2007 11:30 PM
How can we delete backup? S.Vinothkumar Database Support 4 09-28-2007 05:35 AM
oracle import command not found error $enthil Database Support 6 09-08-2007 12:43 AM
Returningclause-update/delete Murali Database Support 0 07-25-2007 07:47 AM


All times are GMT -7. The time now is 02:17 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0