在ASP.NET中删除GridView行 [英] Delete GridView Row in ASP.NET

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

问题描述

如何在ASP.NET中删除GridView行,这是我的代码



 private void gridVIEWData()// 
{
dt1.Columns.Add(ChageCode,typeof(string));
dt1.Columns.Add(USDAmount,typeof(string));
dt1.Columns.Add(LKRamount,typeof(string));
}

if(!IsPostBack)
{
//数据添加到gridview

gridVIEWData();
manifestGrid.DataSource = dt1;
manifestGrid.DataBind();
Session [dt1] = dt1;

}

protected void cmdAdd0_Click(object sender,System.EventArgs e)
{

if(Session [dt2] != null)dt2 =(DataTable)Session [dt2];
DataRow dr = dt2.NewRow();
dr [Shipper] = lblShipper.Text.Trim()。替换(',''');
dr [USDAmountt] = txtUSD.Text;
dr [LKRamountt] = txtLKR.Text;
dt1.Rows.Add(dr);

Cashgrid.DataSource = dt2;
Cashgrid.DataBind();

}

解决方案

使用此





Cashgrid.DeleteRow(Cashgrid.SelectedIndex);


如果行是静态的,请尝试这个..



 protected void GridView1_RowDeleting(object sender,GridViewDeleteEventArgs e)
{
//你的删除代码

}





如果行是动态的,那么请阅读此代码项目文章...



动态添加和删除ASP.NET GridView中的行 [ ^ ]


< asp:GridView ID =   GridView1  runat = quot; server   OnRowDeleting = GridView1_RowDeleting   DataKeyNames = ID  >  







 受保护  void  GridView1_RowDeleting( object  sender,GridViewDeleteEventArgs e)
{

int ID = Utils.ParseInt(GridView1.DataKeys [e.RowIndex] .Values [ 0 ]。ToString());
// 使用ID删除
}


How to Delete GridView Row in ASP.NET,This my code

private void gridVIEWData()//
     {
         dt1.Columns.Add(ChageCode, typeof(string));
         dt1.Columns.Add(USDAmount, typeof(string));
         dt1.Columns.Add(LKRamount, typeof(string));
      }
      
             if (!IsPostBack)
                {
                    //Data add to gridview

                    gridVIEWData();
                    manifestGrid.DataSource = dt1;
                    manifestGrid.DataBind();
                    Session["dt1"] = dt1;

                    } 

protected void cmdAdd0_Click(object sender, System.EventArgs e)
      {

          if (Session["dt2"] != null) dt2 = (DataTable)Session["dt2"];
          DataRow dr = dt2.NewRow();
          dr["Shipper"] = lblShipper.Text.Trim().Replace("'", "''");
          dr["USDAmountt"] = txtUSD.Text;
          dr["LKRamountt"] = txtLKR.Text;
          dt1.Rows.Add(dr);

          Cashgrid.DataSource = dt2;
          Cashgrid.DataBind();

 }

解决方案

Use This


Cashgrid.DeleteRow(Cashgrid.SelectedIndex);


try this if row is static..

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       //Your Delete code
   
   }



if rows are dynamic then read this codeproject article...

Dynamically adding and deleting rows from ASP.NET GridView[^]


<asp:GridView ID="GridView1" runat=quot;server"                    OnRowDeleting="GridView1_RowDeleting" DataKeyNames="ID">




protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       
 int ID= Utils.ParseInt(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
                //Delete with ID
   }


这篇关于在ASP.NET中删除GridView行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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