Click here to Skip to main content
12,352,855 members (65,685 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 C# ASP.NET
Sir !
What is the syntax of delete operation in asp.net website. I want to remove the records from the gridview.
Posted 24-Sep-12 4:03am
Edited 24-Sep-12 4:06am
Nueman9.7K
v2
Comments
joshrduncan2012 24-Sep-12 10:08am
   
Have you tried googling for the answer to see if you can find it yourself?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

For deleting record u can try like that :
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        // Find the unique column of row 
        Label lblId = (Label)gvDetails.Rows[e.RowIndex].FindControl("lblSno");
        DataTable dt = new DataTable();
        dt = Session["Rol"] as DataTable;
      // delete the record from data table 
        for (int i = 0; i < dt.Rows.Count; i++)
        {
             //  
            if (dt.Rows[i][0].ToString() == lblId.Text)
            {
               // write the code for deleting row here .
            }
        }
 
        dt.AcceptChanges();
        Session["Rol"] = dt;
        fnBindGrid();// function for binding grid otherwise  u can  bind here .
    }
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

<asp:gridview id="grid_symptom" cssclass="grid" autogeneratecolumns="False" runat="server" xmlns:asp="#unknown">
                                                    DataKeyNames="symptom_id" 
                                                    OnRowDeleting="grid__symptom_RowDeleting" OnRowEditing="grid_symptom_RowEditing"
                                                    OnRowCancelingEdit="grid_symptom_RowCancelingEdit" OnRowUpdating="grid_symptom_RowUpdating"
                                                    PageSize="3" AllowPaging="True" 
                                                    OnPageIndexChanging="grid_symptom_PageIndexChanging">
                                                    <alternatingrowstyle backcolor="Beige" />
                                                    <pagerstyle cssclass="paging" horizontalalign="Center" />
                                                    <columns>
                                                        <asp:templatefield headertext="Symptoms">
                                                            <edititemtemplate>
                                                                <asp:textbox id="txt_edit_symptom" runat="server" text="<%#Eval ("symptom_name") %>"></asp:textbox>
                                                            </edititemtemplate>
                                                            <itemtemplate>
                                                                <asp:label id="lbl_item_symptom" runat="server" text="<%#Eval ("symptom_name") %>"></asp:label>
                                                            </itemtemplate>
                                                        </asp:templatefield>
                                                        <asp:templatefield headertext="Action">
                                                            <edititemtemplate>
                                                                <asp:imagebutton id="Imgbtn_symptom_Update" commandname="Update" runat="server" imageurl="~/Admin/images/update1.jpg">
                                                                    ToolTip="Update" />
                                                                <asp:imagebutton id="Imgbtn_symptom_Cancel" runat="server" commandname="Cancel" imageurl="~/Admin/images/cancel1.jpg">
                                                                    ToolTip="Cancel" />
                                                            </asp:imagebutton></asp:imagebutton></edititemtemplate>
                                                            <itemtemplate>
                                                                <asp:imagebutton id="Imgbtn_symptom_edit" commandname="Edit" tooltip="Edit" imageurl="~/Admin/images/edit2.png">
                                                                    runat="server" />    
                                                                <asp:imagebutton id="Imgbtn_symptom_delete" commandname="Delete" tooltip="Delete" imageurl="~/Admin/images/delete2.png">
                                                                    OnClientClick="return confirm('Are you sure,Do you want to delete this Symptoms?');"
                                                                    runat="server" />
                                                            </asp:imagebutton></asp:imagebutton></itemtemplate>
                                                        </asp:templatefield>
                                                    </columns>
                                                    <headerstyle cssclass="gridHeader" />
                                                    <footerstyle backcolor="Black" />
                                                    <rowstyle cssclass="gridRow" />
                                                    <pagersettings firstpagetext="<br" mode="hold" />
protected void grid__symptom_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
       MessageHide();
      int i = 0;
      try
      {
          int symptomid = int.Parse(grid_symptom.DataKeys[e.RowIndex].Values[0].ToString());
          bo.Symptom_id= symptomid;
          i = bl.Deletesymptom(bo);
      }
      catch (Exception ex)
      {
          ex.ToString();
      }
      if (i > 0)
      {
          divDeleteSuc.Visible = true;
      }
      else
      {
          divDeleteUsuc.Visible = true;
      }
      bindgridsymptom();
  }
  protected void grid_symptom_RowEditing(object sender,GridViewEditEventArgs e)
  {
      grid_symptom.EditIndex = e.NewEditIndex;
      MessageHide();
      bindgridsymptom();
  }
  protected void grid_symptom_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  {
      grid_symptom.EditIndex = -1;
      MessageHide();
      bindgridsymptom();
  }
  protected void grid_symptom_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
      MessageHide();
      int i = 0;
      try
      {
          TextBox txtsymptom = (TextBox)grid_symptom.Rows[e.RowIndex].FindControl("txt_edit_symptom");
          int symptomid= int.Parse(grid_symptom.DataKeys[e.RowIndex].Values[0].ToString());
          bo.Symptom_id = symptomid;
          bo.Symptom_nm = txtsymptom.Text;
          i = bl.Updatesymptom(bo);
      }
      catch (Exception ex)
      {
          ex.ToString();
      }
      if (i > 0)
      {
          divGridUpdateSuc.Visible = true;
      }
      else
      {
          divGridUpdateUSuc.Visible = true;
      }
      grid_symptom.EditIndex = -1;
      bindgridsymptom();
  }
  protected void grid_symptom_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
      grid_symptom.PageIndex = e.NewPageIndex;
      MessageHide();
      bindgridsymptom();
  }
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

its depend on condition,after click on delete button u r hiting database or after click on save button so tell me what r doing ?
  Permalink  
Comments
tusharkaushik 25-Sep-12 15:01pm
   
after clicking on the button

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100