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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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-- |
|
#2
| |||
| |||
| 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-- |
|
#3
| |||
| |||
| 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....
__________________ S.Balasubramanian Nothing is impossible |
|
#4
| |||
| |||
| But i want a picture in the place of the command "Delete".
__________________ --Kirubhaa. Born to win-- |
|
#5
| |||
| |||
| 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-- |
|
#6
| |||
| |||
| Hi Kirubha, Use imagebutton instead of using Button. <asp:ImageButton id="ImageButton1" runat="server" ImageUrl="url" />
__________________ S.Balasubramanian Nothing is impossible |
|
#7
| |||
| |||
| Thank you balu, I did it.
__________________ --Kirubhaa. Born to win-- |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |
Our Partners |