删除Asp.Net中的值的语法 [英] Syntax of deleting the values in Asp.Net

查看:46
本文介绍了删除Asp.Net中的值的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生!
asp.net网站中删除操作的语法是什么.我想从gridview中删除记录.

Sir !
What is the syntax of delete operation in asp.net website. I want to remove the records from the gridview.

推荐答案

请参阅以下链接:
CP文章:
在ASP.NET Gridview中插入,更新,删除,将数据源作为SQL服务器,MS Access(mdb/accdb),XML和Framework为2.0/3.0/3.5/4.0(VS 2005/2008/2010) [使用Gridview插入,更新,删除...简单方法 [ ^ ]
带有Add_Update_Delete操作的GridView [在ASP.NET 2.0中可编辑GridView [ ^ ]
如何在网格视图中动态创建模板列 [ ^ ]
MSDN文章:
在GridView控件中使用TemplateFields [ ASP.NET的GridView示例:使用TemplateFields [
Refer the links below:
CP Articles:
Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and Framework as 2.0 / 3.0 / 3.5 / 4.0 (VS 2005/2008/2010)[^]
Insert, Update, Delete with Gridview ... Simple Way[^]
GridView with Add_Update_Delete Operations[^]
Editable GridView in ASP.NET 2.0[^]
How to create template columns dynamically in a grid view[^]
MSDN Articles:
Using TemplateFields in the GridView Control[^]
GridView Examples for ASP.NET: Working with TemplateFields[^]


--Amit


要删除记录,您可以这样尝试:
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 .
    }


<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();
  }


这篇关于删除Asp.Net中的值的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆