Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0ASP.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
Nueman7.7K
v2
Comments
joshrduncan2012 at 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 at 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
0 Sergey Alexandrovich Kryukov 545
1 Dnyaneshwar@Pune 500
2 ravikhoda 325
3 OriginalGriff 277
4 Damith Weerasinghe 265
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,777
2 Peter Leow 4,785
3 Abhinav S 3,813
4 Maciej Los 3,575


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